(function () {
    var core = ecui,
        dom = core.dom,
        ui = core.ui,
        util = core.util,
        ext = core.ext,
        esr = ecui.esr,
        iosVersion = /(iPhone|iPad).*?OS (\d+(_\d+)?)/i.test(navigator.userAgent) ? +(RegExp.$2.replace('_', '.')) : undefined;

    // 首页
    ecui.ui.Icon.register('index', 'M38.000,22.000 L38.000,24.000 L38.000,32.000 L38.000,37.000 C38.000,38.657 36.657,40.000 35.000,40.000 L26.000,40.000 L26.000,30.000 C26.000,28.895 25.105,28.000 24.000,28.000 L20.000,28.000 C18.895,28.000 18.000,28.895 18.000,30.000 L18.000,40.000 L8.000,40.000 C6.343,40.000 5.000,38.657 5.000,37.000 L5.000,32.000 L5.000,24.000 L5.000,22.000 L1.000,19.000 C1.000,19.000 18.292,3.242 20.000,2.000 C21.708,0.758 23.000,2.000 23.000,2.000 L42.000,19.000 L38.000,22.000 Z');
    // 审批
    ecui.ui.Icon.register('approval', 'M36.000,40.000 L7.000,40.000 C5.343,40.000 4.000,38.657 4.000,37.000 L4.000,9.000 C4.000,7.343 5.343,6.000 7.000,6.000 L12.000,6.000 L12.000,8.000 C12.000,9.105 12.895,10.000 14.000,10.000 L28.000,10.000 C29.105,10.000 30.000,9.105 30.000,8.000 L30.000,6.000 L36.000,6.000 C37.657,6.000 39.000,7.343 39.000,9.000 L39.000,37.000 C39.000,38.657 37.657,40.000 36.000,40.000 ZM12.000,36.000 C14.761,36.000 17.000,33.761 17.000,31.000 C17.000,28.239 14.761,26.000 12.000,26.000 C9.239,26.000 7.000,28.239 7.000,31.000 C7.000,33.761 9.239,36.000 12.000,36.000 ZM18.751,15.032 C18.133,14.480 17.261,14.448 16.804,14.960 L11.276,20.055 L8.214,17.294 C7.704,16.835 6.841,16.961 6.287,17.576 C5.732,18.192 5.695,19.063 6.205,19.522 L10.071,23.009 C10.127,23.075 10.166,23.150 10.233,23.211 C10.297,23.268 10.372,23.295 10.440,23.341 L10.511,23.405 C10.572,23.460 10.650,23.479 10.720,23.518 C10.726,23.520 10.732,23.525 10.738,23.528 C11.039,23.686 11.395,23.697 11.748,23.569 C11.759,23.565 11.770,23.562 11.781,23.557 C12.018,23.465 12.248,23.335 12.438,23.123 C12.491,23.064 12.517,22.995 12.560,22.932 L19.042,16.958 C19.499,16.446 19.368,15.584 18.751,15.032 ZM35.000,18.000 L22.000,18.000 C20.895,18.000 20.000,18.895 20.000,20.000 C20.000,21.105 20.895,22.000 22.000,22.000 L35.000,22.000 C36.105,22.000 37.000,21.105 37.000,20.000 C37.000,18.895 36.105,18.000 35.000,18.000 ZM35.000,29.000 L22.000,29.000 C20.895,29.000 20.000,29.895 20.000,31.000 C20.000,32.105 20.895,33.000 22.000,33.000 L35.000,33.000 C36.105,33.000 37.000,32.105 37.000,31.000 C37.000,29.895 36.105,29.000 35.000,29.000 ZM12.000,29.000 C13.105,29.000 14.000,29.895 14.000,31.000 C14.000,32.105 13.105,33.000 12.000,33.000 C10.895,33.000 10.000,32.105 10.000,31.000 C10.000,29.895 10.895,29.000 12.000,29.000 ZM26.500,9.000 L15.500,9.000 C14.119,9.000 13.000,7.881 13.000,6.500 C13.000,5.119 14.119,4.000 15.500,4.000 L26.500,4.000 C27.881,4.000 29.000,5.119 29.000,6.500 C29.000,7.881 27.881,9.000 26.500,9.000 Z');
    // 账本
    ecui.ui.Icon.register('bill', 'M41.000,25.859 L41.000,33.000 C41.000,35.209 39.209,37.000 37.000,37.000 L6.000,37.000 C3.791,37.000 2.000,35.209 2.000,33.000 L2.000,25.859 C3.722,25.412 5.000,23.862 5.000,22.000 C5.000,20.138 3.722,18.588 2.000,18.141 L2.000,10.000 C2.000,7.791 3.791,6.000 6.000,6.000 L37.000,6.000 C39.209,6.000 41.000,7.791 41.000,10.000 L41.000,18.141 C39.278,18.588 38.000,20.138 38.000,22.000 C38.000,23.862 39.278,25.412 41.000,25.859 ZM28.347,12.084 C27.717,11.454 26.696,11.454 26.065,12.083 L21.404,16.740 L17.257,11.976 C16.672,11.304 15.653,11.234 14.981,11.819 C14.309,12.404 14.239,13.423 14.824,14.095 L19.003,18.895 L17.212,18.894 C16.215,18.894 15.405,19.702 15.405,20.700 C15.404,21.698 16.213,22.507 17.211,22.508 L19.737,22.509 L19.736,23.755 L17.387,23.754 C16.428,23.753 15.650,24.530 15.650,25.490 C15.649,26.449 16.426,27.227 17.386,27.227 L19.735,27.229 L19.734,29.193 C19.733,30.295 20.626,31.189 21.729,31.190 C22.832,31.191 23.726,30.297 23.726,29.195 L23.727,27.231 L26.070,27.232 C27.029,27.232 27.807,26.455 27.808,25.496 C27.808,24.536 27.031,23.758 26.072,23.758 L23.729,23.757 L23.730,22.511 L26.245,22.512 C27.243,22.513 28.052,21.704 28.053,20.706 C28.053,19.708 27.245,18.899 26.247,18.899 L23.809,18.897 L28.345,14.366 C28.976,13.736 28.976,12.715 28.347,12.084 Z');
    // 我的
    ecui.ui.Icon.register('me', 'M21.000,1.000 C27.627,1.000 33.000,6.373 33.000,13.000 C33.000,19.627 27.627,25.000 21.000,25.000 C14.373,25.000 9.000,19.627 9.000,13.000 C9.000,6.373 14.373,1.000 21.000,1.000 ZM21.000,27.000 C32.046,27.000 41.000,30.134 41.000,34.000 C41.000,37.866 32.046,41.000 21.000,41.000 C9.954,41.000 1.000,37.866 1.000,34.000 C1.000,30.134 9.954,27.000 21.000,27.000 Z');
    // 锁定
    ecui.ui.Icon.register('lock', 'M8,11.5384584 C8.8800089,11.5384584 9.60001114,12.2307681 9.60001114,13.0769303 C9.60001114,13.6153874 9.27999779,14.1442388 8.80000557,14.3750176 L8.80000557,16.153874 C8.80000557,16.6154048 8.47999222,16.9231099 8,16.9231099 C7.52000778,16.9231099 7.19999443,16.6154048 7.19999443,16.153874 L7.19999443,14.3750176 C6.72000221,14.1442388 6.39998886,13.6154142 6.39998886,13.0769303 C6.39998886,12.2307681 7.12001892,11.5384584 8,11.5384584 Z M8,0 C5.34093945,0 3.19999443,2.05860043 3.19999443,4.61538873 L3.19999443,7.69230563 C1.44000445,7.69230563 0,9.07692493 0,10.7692225 L0,16.9230831 C0,18.6154075 1.44000445,20 3.19999443,20 L12.8000056,20 C14.5599956,20 16,18.6153807 16,16.9230831 L16,10.7692225 C16,9.07692493 14.5599956,7.69230563 12.8000056,7.69230563 L4.80000557,7.69230563 L4.80000557,4.61538873 C4.80000557,2.86446662 6.17906836,1.53847184 8,1.53847184 C9.82095949,1.53847184 11.1999944,2.8644934 11.1999944,4.61538873 L11.1999944,7.69230563 L12.8000056,7.69230563 L12.8000056,4.61538873 C12.8000056,2.05860043 10.6590606,0 8,0 Z');
    // 标签
    ecui.ui.Icon.register('tag', 'M108.35,92H51.19a6,6,0,0,0,0,12h57.16a6,6,0,0,0,0-12ZM135.22,68.75h-84a6,6,0,0,0,0,12h84a6,6,0,0,0,0-12ZM135.22,45.51h-84a6,6,0,0,0,0,12h84a6,6,0,0,0,0-12ZM136.47,3.25H52.53a26.06,26.06,0,0,0-26,26V165.81a20.46,20.46,0,0,0,20.44,20.44h2.54a23.58,23.58,0,0,0,17.62-7.91l5.25-5.9a1.3,1.3,0,0,1,1.79-.14l8,6.44a16.86,16.86,0,0,0,22.58-1.18l5.18-5.19a1.31,1.31,0,0,1,1.78-.05l8.85,7.92a23.54,23.54,0,0,0,15.73,6h5.84a20.46,20.46,0,0,0,20.44-20.44V29.28A26.06,26.06,0,0,0,136.47,3.25Zm14,162.56a8.45,8.45,0,0,1-8.44,8.44h-5.84a11.59,11.59,0,0,1-7.73-2.95l-8.85-7.92a13.3,13.3,0,0,0-18.26.51l-5.19,5.18a4.88,4.88,0,0,1-6.54.35l-8-6.45a13.28,13.28,0,0,0-18.3,1.49l-5.25,5.91a11.63,11.63,0,0,1-8.66,3.88H46.94a8.45,8.45,0,0,1-8.44-8.44V29.28a14,14,0,0,1,14-14h83.94a14,14,0,0,1,14,14Z');
    // 定位
    ecui.ui.Icon.register('position', 'M141.66,121a6,6,0,0,0-4,11.32c13,4.6,21.11,11.12,21.11,17,0,11.16-27.6,23.63-64.53,23.63S29.7,160.5,29.7,149.34c0-5.75,7.82-12.17,20.41-16.76A6,6,0,1,0,46,121.31c-18.26,6.64-28.31,16.6-28.31,28C17.7,169.65,50.6,185,94.23,185s76.53-15.32,76.53-35.63C170.76,137.72,160.42,127.67,141.66,121ZM48.72,112,90,153.25a6,6,0,0,0,8.48,0L139.74,112a62.72,62.72,0,0,0,0-88.72l-1.15-1.16a62.81,62.81,0,0,0-88.72,0l-1.16,1.16h0a62.72,62.72,0,0,0,0,88.72ZM57.2,31.74h0l1.15-1.15a50.78,50.78,0,0,1,71.75,0l1.16,1.15a50.73,50.73,0,0,1,0,71.75l-37,37-37-37a50.73,50.73,0,0,1,0-71.75ZM94.23,104.61a37,37,0,1,0-37-37A37,37,0,0,0,94.23,104.61Zm0-62a25,25,0,1,1-25,25A25,25,0,0,1,94.23,42.63Z');
    // 时间
    ecui.ui.Icon.register('time', 'M94.49,3.33A90.64,90.64,0,1,0,185.12,94,90.74,90.74,0,0,0,94.49,3.33Zm0,169.27A78.64,78.64,0,1,1,173.12,94,78.73,78.73,0,0,1,94.49,172.6ZM91,101.56V46.41a6,6,0,0,0-12,0v57.72a6,6,0,0,0,1.88,4.36l39.41,37.39a6,6,0,0,0,8.25-8.71Z');
    // 菜单-账本
    ecui.ui.Icon.register('book', 'M7.49988344,1.80161032e-06 C8.28370669,-0.00089937329 9.02983243,0.336317154 9.54707702,0.925246468 L11.168468,0.848199716 C11.7296738,0.821398042 12.2498731,1.14154082 12.4788224,1.65462225 C12.7077716,2.16770368 12.5986005,2.7686866 12.2038263,3.16846607 L11.0293747,4.35723609 C12.5314455,5.22077337 13.7328293,6.61818327 14.4173863,8.31628005 C15.0163737,9.80062324 15.1534214,11.4653104 14.8288705,13.3093187 C14.6567479,14.2873029 13.8070792,15.0002563 12.8140639,15.0002563 L2.18570302,15.0002563 C1.19268773,15.0002563 0.343018999,14.2873029 0.170896356,13.3093187 C-0.153313651,11.4653104 -0.0162658878,9.80130507 0.582380559,8.31628005 C1.26761937,6.61750144 2.46968508,5.21940971 3.97277858,4.35621335 L2.79934972,3.16880699 C2.40443031,2.76914724 2.29506517,2.16817822 2.52386745,1.65501278 C2.75266973,1.14184734 3.27279647,0.821546434 3.83402624,0.848199716 L5.4533717,0.925246468 C5.97045943,0.336496151 6.71629799,-0.000702888651 7.49988344,1.80161032e-06 Z M9.20276717,6.05416975 C8.95932981,5.913617 8.64808755,5.99590446 8.50592311,6.23840414 L8.50592311,6.23840414 L7.49988344,7.98047894 L6.49384377,6.23840414 C6.35167933,5.99590446 6.04043708,5.913617 5.79699972,6.05416975 C5.55356236,6.19472249 5.46921216,6.50541207 5.60814703,6.74977639 L5.60814703,6.74977639 L6.4348655,8.18195961 L5.62485186,8.18195961 C5.34242876,8.18195961 5.11347961,8.41090876 5.11347961,8.69333186 C5.11347961,8.97575495 5.34242876,9.20470411 5.62485186,9.20470411 L5.62485186,9.20470411 L6.98851119,9.20470411 L6.98851119,10.2274486 L5.62485186,10.2274486 C5.34242876,10.2274486 5.11347961,10.4563978 5.11347961,10.7388209 C5.11347961,11.021244 5.34242876,11.2501931 5.62485186,11.2501931 L5.62485186,11.2501931 L6.98851119,11.2501931 L6.98851119,12.7843099 C6.9885112,13.0667329 7.21746035,13.2956821 7.49988344,13.2956821 C7.78230653,13.2956821 8.01125568,13.0667329 8.01125569,12.7843099 L8.01125569,12.7843099 L8.01125569,11.2501931 L9.37491502,11.2501931 C9.65733812,11.2501931 9.88628727,11.021244 9.88628727,10.7388209 C9.88628727,10.4563978 9.65733812,10.2274486 9.37491502,10.2274486 L9.37491502,10.2274486 L8.01125569,10.2274486 L8.01125569,9.20470411 L9.37491502,9.20470411 C9.65733812,9.20470411 9.88628727,8.97575495 9.88628727,8.69333186 C9.88628727,8.41090876 9.65733812,8.18195961 9.37491502,8.18195961 L9.37491502,8.18195961 L8.56456047,8.18161869 L9.39161985,6.74977639 C9.53055473,6.50541207 9.44620453,6.19472249 9.20276717,6.05416975 Z');
    // 搜索
    // 放大镜搜索
    ecui.ui.Icon.register('search', 'M13.3290801,14 C13.1546025,14.000546 12.9868229,13.9328412 12.861569,13.8113367 L10.7639671,11.7325701 C10.7308263,11.6987195 10.7011633,11.6616292 10.6754233,11.6218561 L10.6231825,11.5332849 L10.545264,11.5952847 C9.39805997,12.5070974 7.9764608,13.004312 6.51120982,13.0062243 L6.50235544,13.0062243 C3.46923198,13.0066116 0.838922987,10.908809 0.16374989,7.95087022 C-0.511423208,4.99293143 0.947991754,1.96103783 3.6806963,0.644512825 C6.41340085,-0.672012184 9.69307791,0.0767464926 11.5841705,2.44889623 C13.4752631,4.82104597 13.4751435,8.18610045 11.5838824,10.5581157 L11.5219017,10.6351727 L11.6060183,10.6883154 C11.6460871,10.7140147 11.6834644,10.7436884 11.7175835,10.7768866 L13.8196126,12.8609675 C14.0661655,13.1278194 14.0591429,13.541498 13.8036747,13.7998224 C13.6774667,13.9269568 13.5055354,13.9981118 13.3264238,13.9973362 L13.3290801,14 Z M6.50501175,1.21650902 C4.36512766,1.21615085 2.43575121,2.50530987 1.61660485,4.4828151 C0.797458493,6.46032032 1.2498718,8.73670522 2.76287174,10.2504276 C4.27587168,11.7641499 6.55147531,12.2170845 8.52850473,11.3980152 C10.5055341,10.5789459 11.7946166,8.64918706 11.7946166,6.50863952 C11.791689,3.5874362 9.42530918,1.21992653 6.50501175,1.21650902 Z');
    // 复选框-选中
    ecui.ui.Icon.register('checkbox-checked', 'M6.99984069,3.29548898e-16 C3.14081526,3.29548898e-16 -4.31940105e-16,3.14049662 -4.31940105e-16,6.99984067 C-4.31940105e-16,10.8591847 3.14049662,14 6.99984069,14 C10.8591848,14 14,10.8595034 14,6.99984067 C13.9996814,3.14049662 10.8591847,3.29548898e-16 6.99984069,3.29548898e-16 Z M10.9168582,5.65773721 L6.36383913,10.3248287 C6.2547105,10.4361461 6.10549574,10.4990459 5.94960966,10.4994427 L5.94642328,10.4994427 C5.79186529,10.4996106 5.64356309,10.4384101 5.53410565,10.3292897 L3.08728406,7.88087488 C2.97775549,7.77154976 2.91620585,7.62315092 2.91620585,7.46839793 C2.91620585,7.31364493 2.97775549,7.16524609 3.08728406,7.05592097 C3.19660918,6.9463924 3.34500802,6.88484276 3.49976102,6.88484276 C3.65451401,6.88484276 3.80291285,6.9463924 3.91223797,7.05592097 L5.94355555,9.08564535 L10.0826638,4.84043062 C10.308066,4.61054104 10.6769491,4.60626661 10.9076177,4.83087147 C11.1376402,5.05702011 11.1417693,5.42650454 10.9168582,5.65773721 L10.9168582,5.65773721 Z');
    // 删除按钮
    ecui.ui.Icon.register('delete', 'M11.76,2.43055556 L9.065,2.43055556 L9.065,1.45833333 C9.065,0.65625 8.4035,0 7.595,0 L4.655,0 C3.8465,0 3.185,0.65625 3.185,1.45833333 L3.185,2.43055556 L0.49,2.43055556 C0.2205,2.43055556 0,2.64930556 0,2.91666667 C0,3.18402778 0.2205,3.40277778 0.49,3.40277778 L1.225,3.40277778 L1.225,11.1805556 C1.225,12.25 2.107,13.125 3.185,13.125 L9.065,13.125 C10.143,13.125 11.025,12.25 11.025,11.1805556 L11.025,3.40277778 L11.76,3.40277778 C12.0295,3.40277778 12.25,3.18402778 12.25,2.91666667 C12.25,2.64930556 12.0295,2.43055556 11.76,2.43055556 Z M4.165,1.45833333 C4.165,1.19097222 4.3855,0.972222222 4.655,0.972222222 L7.595,0.972222222 C7.8645,0.972222222 8.085,1.19097222 8.085,1.45833333 L8.085,2.43055556 L4.165,2.43055556 L4.165,1.45833333 Z M10.045,11.1805556 C10.045,11.7152778 9.604,12.1527778 9.065,12.1527778 L3.185,12.1527778 C2.646,12.1527778 2.205,11.7152778 2.205,11.1805556 L2.205,3.40277778 L10.045,3.40277778 L10.045,11.1805556 ZM4.655,5.34722222 C4.3855,5.34722222 4.165,5.56597222 4.165,5.83333333 L4.165,9.72222222 C4.165,9.98958333 4.3855,10.2083333 4.655,10.2083333 C4.9245,10.2083333 5.145,9.98958333 5.145,9.72222222 L5.145,5.83333333 C5.145,5.56597222 4.9245,5.34722222 4.655,5.34722222 Z M7.595,5.34722222 C7.3255,5.34722222 7.105,5.56597222 7.105,5.83333333 L7.105,9.72222222 C7.105,9.98958333 7.3255,10.2083333 7.595,10.2083333 C7.8645,10.2083333 8.085,9.98958333 8.085,9.72222222 L8.085,5.83333333 C8.085,5.56597222 7.8645,5.34722222 7.595,5.34722222 Z');
    // 排序-升序
    ecui.ui.Icon.register('sortAsc', 'M2.44798766,4.26870965 L9.55435128,4.26870965 C9.8869151,4.26870965 10.1144588,4.05866934 9.93942517,3.8661324 C9.74688823,3.67359545 6.52627023,0.27794387 6.38624336,0.137917001 C6.22871314,-0.0371165855 5.80863253,-0.0546199442 5.59859222,0.137917001 C5.45856535,0.312950588 2.32546415,3.58607866 2.06291377,3.8661324 C1.88788019,4.04116598 2.09792049,4.26870965 2.44798766,4.26870965 Z');
    // 排序-降序
    ecui.ui.Icon.register('sortDesc', 'M7.55435128,4.26325641e-14 L0.447987664,4.26325641e-14 C0.0979204905,4.26325641e-14 -0.112119813,0.227543663 0.0629137732,0.402577249 C0.325464153,0.682630988 3.45856535,3.95575906 3.61609558,4.11328929 C3.80863253,4.32332959 4.22871314,4.28832287 4.40374672,4.11328929 C4.52627023,3.99076578 7.74688823,0.595114195 7.93942517,0.402577249 C8.11445876,0.210040304 7.8869151,0.0175033587 7.55435128,4.26325641e-14 Z');
    // 编辑
    ecui.ui.Icon.register('edit', 'M4.45871936,7.53912201 C4.449684,7.55062154 4.44064866,7.562741 4.43658818,7.57732464 L3.73914612,10.134359 C3.69847932,10.283233 3.740138,10.4436531 3.85034444,10.5567422 C3.93277843,10.6372699 4.04138858,10.6815322 4.15706583,10.6815322 C4.19526846,10.6815322 4.23354857,10.6769603 4.27122426,10.6669486 L6.81011046,9.97448143 C6.81418644,9.97448143 6.81615468,9.97804597 6.81922329,9.97804597 C6.84839057,9.97804597 6.87704641,9.96742982 6.89868166,9.94531414 L13.6877613,3.15722636 C13.8894216,2.95530262 14,2.68024369 14,2.38097685 C14,2.04188009 13.8561783,1.70292283 13.60432,1.45173087 L12.9631512,0.809539266 C12.7116803,0.557680888 12.3722426,0.413595759 12.0333008,0.413595759 C11.7341115,0.413595759 11.4590681,0.524205148 11.2568963,0.72561747 L4.46882407,7.51551852 C4.46177246,7.5219967 4.46375621,7.53158998 4.45871936,7.53912201 M13.0234541,2.49242315 L12.3491041,3.16626171 L11.25592,2.05571985 L11.9207077,1.39091663 C12.0257533,1.2852976 12.2294283,1.30070264 12.3501269,1.42183519 L12.9917296,2.06402679 C13.0586811,2.13086977 13.0968527,2.21985942 13.0968527,2.30785718 C13.0964497,2.37998498 13.070754,2.44543314 13.0234541,2.49242315 M5.66610838,7.64577942 L10.5650026,2.74660624 L11.6587291,3.85789201 L6.76894772,8.74744092 L5.66610838,7.64577942 L5.66610838,7.64577942 Z M4.7735617,9.63202159 L5.12758304,8.33258982 L6.0719086,9.27700837 L4.7735617,9.63202159 L4.7735617,9.63202159 Z M13.0814941,5.18243058 C12.8245059,5.18243058 12.5982968,5.39137493 12.5973049,5.65185021 L12.5973049,12.0038546 C12.5973049,12.3357293 12.3277788,12.5931049 11.9953772,12.5931049 L1.55301043,12.5931049 C1.22112026,12.5931049 0.973756316,12.3357603 0.973756316,12.0038546 L0.973756316,1.55017431 C0.973756316,1.21803617 1.22110477,0.967975556 1.55301043,0.967975556 L8.71942047,0.967975556 C8.97785001,0.967975556 9.18753827,0.738325848 9.18753827,0.479818808 C9.18753827,0.221823216 8.97783452,0 8.71942047,0 L1.48159554,0 C0.672474732,0 0,0.669654118 0,1.47925536 L0,12.0753005 C0,12.8849327 0.672490241,13.5659159 1.48159554,13.5659159 L12.0662341,13.5659159 C12.8759439,13.5659159 13.5650945,12.8849327 13.5650945,12.0753005 L13.5650945,5.64889009 C13.5641026,5.39137493 13.3384204,5.18243058 13.0814941,5.18243058');
    // 切换图标
    ecui.ui.Icon.register('toggle', 'M13.3239981,8.62068157 L0.676001931,8.62068157 C0.302510864,8.62068157 0,8.92319243 0,9.2966835 C0,9.43864391 0.0439401255,9.57046428 0.118300338,9.67862459 C0.15041043,9.75467481 0.19942057,9.82565501 0.260260744,9.88818519 L3.23973926,12.8659737 C3.37155963,12.9977941 3.54394013,13.0637043 3.71801062,13.0637043 C3.89208112,13.0637043 4.06446161,12.9977941 4.19628199,12.8659737 C4.45992274,12.6023329 4.45992274,12.1747617 4.19628199,11.909431 L2.25615645,9.97268543 L13.3223081,9.97268543 C13.6957991,9.97268543 13.99831,9.67017457 13.99831,9.2966835 C13.99831,8.92319243 13.6974891,8.62068157 13.3239981,8.62068157 L13.3239981,8.62068157 Z M0.676001931,5.48403261 L13.3239981,5.48403261 C13.6974891,5.48403261 14,5.18152174 14,4.80803068 C14,4.66607027 13.9560599,4.53424989 13.8816997,4.42608958 C13.8580396,4.37031942 13.8242395,4.31623927 13.7836794,4.26553913 L11.3466924,1.28775062 C11.1100917,0.998759791 10.6842105,0.956509671 10.3952197,1.19311035 C10.1062289,1.42971102 10.0639788,1.85559224 10.3005794,2.14458307 L11.9280541,4.13202874 L0.676001931,4.13202874 C0.302510864,4.13202874 0,4.43453961 0,4.80803068 C0,5.18152174 0.302510864,5.48403261 0.676001931,5.48403261 L0.676001931,5.48403261 Z');
    // 添加图标
    ecui.ui.Icon.register('add', 'M7,14 C3.1339939,14 0,10.8660061 0,7 C0,3.1339939 3.1339939,0 7,0 C10.8660061,0 14,3.1339939 14,7 C14,10.8660061 10.8655793,14 7,14 Z M7.01280487,1.09118903 C3.74307927,1.09118903 1.09246951,3.73945121 1.09246951,7.00640244 C1.09246951,10.2733537 3.74307927,12.9216158 7.01280487,12.9216158 C10.2825305,12.9216158 12.9329268,10.2733537 12.9329268,7.00640244 C12.9329268,3.73945123 10.2823171,1.09118903 7.01259147,1.09118903 L7.01280487,1.09118903 Z M9.38640244,7.53503049 L7.56939024,7.53503049 L7.56939024,9.38042684 C7.56939024,9.67791973 7.3282246,9.91908537 7.0307317,9.91908537 C6.73323881,9.91908537 6.49207316,9.67791973 6.49207316,9.38042684 L6.49207316,7.53503049 L4.65990853,7.53503049 C4.36335856,7.53503049 4.12295731,7.29462924 4.12295731,6.99807927 C4.12295731,6.7015293 4.36335856,6.46112805 4.65990853,6.46112805 L6.49207316,6.46112805 L6.49207316,4.42728658 C6.49207316,4.12979369 6.73323881,3.88862804 7.0307317,3.88862804 C7.3282246,3.88862804 7.56939024,4.12979369 7.56939024,4.42728658 L7.56939024,6.46112805 L9.38640244,6.46112805 C9.68295241,6.46112805 9.92335367,6.7015293 9.92335367,6.99807927 C9.92335367,7.29462924 9.68295241,7.53503049 9.38640244,7.53503049 Z');
    // 上传图标
    ecui.ui.Icon.register('upload', 'M13.4283333,8.2270847 C13.7409449,8.23404187 13.9926124,8.47104662 14,8.76544477 C14,10.5629082 12.6256667,12 10.948,12 L10.948,12 L3.052,12 C1.37433333,12 0,10.5629082 0,8.76544477 C0.00738759479,8.47104662 0.259055054,8.23404187 0.571666667,8.2270847 C0.88427828,8.23404187 1.13594574,8.47104662 1.14333333,8.76544477 C1.14333333,9.96302127 1.98333333,10.9210825 3.052,10.9210825 L3.052,10.9210825 L10.948,10.9210825 C12.0166667,10.9210825 12.8566667,9.95203433 12.8566667,8.76544477 C12.8640543,8.47104662 13.1157217,8.23404187 13.4283333,8.2270847 Z M6.524,0.145091403 C6.7654397,-0.0483638011 7.12022696,-0.0483638011 7.36166667,0.145091403 L7.36166667,0.145091403 L9.45933333,2.19305708 C9.61739247,2.32458624 9.68485996,2.52786998 9.63446991,2.72075445 C9.58407986,2.91363891 9.4241619,3.0642397 9.2193443,3.11169391 C9.0145267,3.15914812 8.79866645,3.09561144 8.659,2.94676118 L8.659,2.94676118 L7.476,1.83268544 L7.476,7.93922686 C7.47600001,8.1315644 7.36704096,8.30929161 7.19016667,8.40546038 C7.01329239,8.50162915 6.79537428,8.50162915 6.61849999,8.40546038 C6.44162571,8.30929161 6.33266666,8.1315644 6.33266667,7.93922686 L6.33266667,7.93922686 L6.33266667,1.83268544 L5.14966667,2.94676118 C4.92518101,3.13356728 4.58511916,3.12368464 4.37329168,2.9241987 C4.1614642,2.72471277 4.15097015,2.40446369 4.34933333,2.19305708 L4.34933333,2.19305708 Z');


    function getQueryUrl(listview, route, pageNo) {
        if (listview._sReqUrl) {
            var url = listview._sReqUrl;
            var resUrl = listview._sView + 'Data@FORM ' + url;
        } else {
            var url = route[listview._sUrlName || 'queryUrl'];
            var resUrl = (listview._sUrlName || route.view) + 'Data' + url;
        }
        if (!listview._bNoPage) {
            resUrl = resUrl  + (url.indexOf('?') < 0 ? '?' : '&') + 'pageNo=' + pageNo;
        }
        return resUrl;
    }

    mao.ui.MTimerCalendar = core.inherits(
        ecui.ui.MCalendar,
        function (el, options) {
            ecui.ui.MCalendar.call(this, el, options);
            this._uHour = this.getOptions(3);
            this._uMinute = this.getOptions(4);
            this._uSecond = this.getOptions(5);
        },
        {
            /**
             * 确认事件的默认处理。
             * @event
             */
            $confirm: function () {
                var month = this._uMonth.getValue(),
                    date = this._uDate.getValue(),
                    hour = this._uHour.getValue(),
                    minute = this._uMinute.getValue(),
                    second = this._uSecond.getValue();

                this.setValue(this._uYear.getValue() + '-' + (+month < 10 ? '0' + month : month) + '-' + (+date < 10 ? '0' + date : date) + ' ' + (+hour < 10 ? '0' + hour : hour) + ':' + (+minute < 10 ? '0' + minute : minute) + ':' + (+second < 10 ? '0' + second : second));
            },
            getFormValue: function () {
                return this.getValue();
            }
        }
    );

    mao.ui.UeContent = ecui.inherits(
        ecui.ui.Control,
        function (el, options) {
            ecui.ui.Control.call(this, el, options);
            el.innerHTML = ecui.dom.getText(el);
        }
    );

    var autoRequestListView = {
        HTML_PREPARE: '<img class="refresh-gif" src="images/base/refresh.gif"><span>正在刷新...</span>',

        $loaddata: function () { // 拖拽到底部的事件，上拉加载数据
            if (this._pullupLoad === '0') {         // ### 只是为了解决同步列表上拉不加载新数据问题
                this.HTML_LOADING = '没有更多数据';   // ###
                this.requestData(-1);               // ###
            } else {                                // ###
                this.requestData(this._nPageNo + 1);
            }                                       // ###
        },
        $refresh: function () { // 在顶部下拉刷新数据, 只取第一页的数据
            this.requestData(1, true);
        },
        changeItems: function (items, refresh) {
            if (!iosVersion) {
                util.timer(function () {
                    this._eMain && this.alterStatus('-init');              
                }, 320, this);
            } else {
                this.alterStatus('-init');
            }
            if (refresh) {
                this._eMain && this.reload(items);
            } else {
                this.add(items);
            }
        },
        // 
        handleDataItem: function (data, index) {
            return data;
        },
        handleData: function (list, page) {
            return list;
        },
        init: function () {
            ecui.ui.MListView.prototype.init.call(this);
            if (this._bInitRefresh) {
                ecui.dispatchEvent(this, 'refresh', { isInit: true });
            }
        },
        requestData: function (pageNo, refresh) {
            var route = ecui.esr.findRoute(this);
            var view = this._sView || route.view;
            var url = getQueryUrl(this, route, pageNo);
            if (!this._bNoPage) {
                url = url + '&pageSize=' + this._nPageSize;
            }
            ecui.esr.request(
                url,
                function () {
                    var listName = this._sUrlName || view,
                        data = ecui.esr.getData(listName + 'Data'),
                        listData = data.record || data;
                    ecui.dispatchEvent(this, 'request', { data: data });
                    listData = this.handleData(listData, pageNo);
                    if (listData.length || this._bPage === 'sp-com-det-list') {
                        var el = ecui.dom.create('div'),
                            ElList = [],
                            renderer = ecui.esr.getEngine().getRenderer(view + 'Item'),
                            global = ecui.esr.getGlobal();

                        if (this._bPage === 'sp-com-det-list' && refresh) {
                            var labelList = { '': 0, '100': 0, '101': 0 };
                            data.labelList.forEach(function (item) {
                                labelList[item.labelId] = item.labelCount;
                                labelList[''] += item.labelCount;
                                labelList[+item.labelId <= 6 ? '100' : '101'] += item.labelCount;
                            });
                            ElList.push(ecui.esr.getEngine().render('detail.tagItems', {
                                Global: global,
                                NS: ecui.esr.getData('NS'),
                                options: this._oOptions,
                                length: listData.length,
                                labelList: labelList
                            }));
                        }
                        listData.forEach(function (item, index) {
                            item = this.handleDataItem(item, index);
                            // 根据一条条列表数据生成一个个对应的div
                            ElList.push(
                                renderer({
                                    item: item,
                                    Global: global,
                                    NS: ecui.esr.getData('NS'),
                                    options: this._oOptions,
                                    pageNo: pageNo,
                                    index: index,
                                })
                            );
                        }.bind(this));
                        el.innerHTML = ElList.join('');
                        this.changeItems(dom.children(el), pageNo === 1);
                    } else {
                        this.changeItems([], refresh);
                    }
                    this._nPageNo = pageNo;
                    this.refreshStatus = false;
                }.bind(this),
                function (error) {
                    this.refreshStatus = false;
                    this.add([]);
                    if (error && error[0].xhr.status >= 500) {
                        ecui.esr.showSelect(ecui.esr.getEngine().render('server-error', {}), function () {}, '服务器错误');
                    }
                    return false;
                }.bind(this)
            );
        },
        setUrlName: function (name) {
            this._sUrlName = name;
        },
        setPosition: function (x, y) {
            ui.MListView.prototype.setPosition.call(this, x, y);
            if (y === this.getHeader().offsetHeight && !this.refreshStatus) {
                this.refreshStatus = true;
                this.getHeader().firstChild.innerHTML = this.prerefresh;
            }
        }
    };


    // 继承ecui中的滚动列表控件，实现上拉加载和下拉刷新
    mao.ui.AppListView1 = ecui.inherits(
        ecui.ui.MListView,
        function (el, options) {
            ecui.ui.MListView.call(this, el, options);
            this._sRoute = options.route;
            this._nPageSize = +options.pageSize || 10;
            this._nPageNo = +options.pageNo || 1;
            this._sData = options.data || '';
            this._sReqUrl = options.reqUrl || '';
            // var refres = ecui.esr.getEngine().render('refresh');
            this.refreshed = ecui.esr.getEngine().render('refresh', {status: 0});
            this.prerefresh = ecui.esr.getEngine().render('refresh', {status: 1});
            this.refreshing = ecui.esr.getEngine().render('refresh', {status: 2});
            this.HTML_PREPARE = this.refreshing;
            this.HTML_REFRESH = this.refreshed;
            this.HTML_REFRESHED = this.refreshed;
            this.HTML_NODATA = '没有更多内容了...';
        },
        {
            HTML_PREPARE: '<img class="refresh-gif" src="images/base/refresh.gif"><span>正在刷新...</span>',
            $loaddata: function () { // 拖拽到底部的事件，上拉加载数据
                this.requestData(this._nPageNo + 1);
            },
            $refresh: function () { // 在顶部下拉刷新数据, 只取第一页的数据
                this.requestData(1, true);
            },
            setPosition: function (x, y) {
                ui.MListView.prototype.setPosition.call(this, x, y);
                if (y === this.getHeader().offsetHeight && !this.refreshStatus) {
                    this.refreshStatus = true;
                    this.getHeader().firstChild.innerHTML = this.prerefresh;
                }
            },
            requestData: function (pageNo, refresh) {
                var route = esr.findRoute(this);
                var url = this._sReqUrl;
                url = this._sData + 'Data@FORM ' + url + '&pageNo=' + pageNo;
                esr.request(
                    url,
                    function () {
                        var listData = esr.getData(this._sData + 'Data');
                        listData = this.handleData(util.parseValue('data.record', listData) || [], pageNo);

                        if (listData.length) {
                            var el = dom.create('div'),
                                ElList = [],
                                renderer = esr.getEngine().getRenderer((this._sListView || route.view) + 'Item');

                            listData.forEach(function (item, index) {
                                item = this.handleData(item, index);
                                ElList.push(
                                    renderer({
                                        item: item,
                                        pageNo: pageNo,
                                        index: index
                                    })
                                );
                            }.bind(this));
                            el.innerHTML = ElList.join('');
                            ecui.init(el);
                            this.changeItems(dom.children(el), pageNo === 1);

                        } else {
                            this.changeItems([], refresh);
                        }
                        this._nPageNo = pageNo;
                        this.refreshStatus = false;
                    }.bind(this),
                    function (error) {
                        this.refreshStatus = false;
                        this.changeItems([]);
                        if (error && error[0].xhr.status >= 500) {
                            esr.showSelect(esr.getEngine().render('server-error', {}), function () {}, '服务器错误');
                        }
                        return false;
                    }.bind(this)
                );
            },
            changeItems: function (arr, refresh) {
                if (!iosVersion) {
                    util.timer(function () {
                        this._eMain && this.alterStatus('-init');              
                    }, 320, this);
                } else {
                    this.alterStatus('-init');
                }
                if (refresh) {
                    this._eMain && this.reload(arr);
                } else {
                    this.add([]);
                }
            },
            // 
            handleDataItem: function (data, index) {
                return data;
            },
            handleData: function (list, page) {
                return list;
            }
        }
    );

    // 继承ecui中的滚动列表控件，实现上拉加载和下拉刷新
    mao.ui.AppListView = ecui.inherits(
        ecui.ui.MListView,
        function (el, options) {
            ecui.ui.MListView.call(this, el, options);
            this._nPageSize = +options.pageSize || 10;
            this._sUrlName = options.urlName;
            this._bPage = options.page;
            this._sPageName = options.pageName;
            this._pullupLoad = options.pullupLoad; //是否上拉加载, 1.5.1(包含)之前的同步列表没做分页,故做此处理, 如果接口完善,请删除有###注释的行
            this._bNoPage = options.noPage;
            this._sView = options.view;
            this._sReqUrl = options.reqUrl;
            this._bInitRefresh = options.initRefresh;
            this._oOptions = options;
        },
        autoRequestListView
    );

    mao.ui.AppOpListView = ecui.inherits(
        ecui.ui.MOpListView,
        function (el, options) {
            ecui.ui.MOpListView.call(this, el, options);
            this._nPageSize = +options.pageSize || 10;
            this._sUrlName = options.urlName;
        },
        autoRequestListView
    );

    mao.ui.RefreshListView = ecui.inherits(
        mao.ui.AppListView,
        function (el, options) {
            mao.ui.AppListView.call(this, el, options);
            this._sRouteName = options.routeName;
            this._bChild = options.child;
            this._bInitRefresh = false;
        },
        {
            $refresh: function () { // 在顶部下拉刷新数据, 只取第一页的数据
                var route = ecui.esr.findRoute(this);
                if (this._sRouteName) {
                    route = ecui.esr.getRoute(this._sRouteName);
                }

                delete route.CACHE;
                ecui.esr.callRoute(route.NAME, this._bChild);
            }
        }
    )

    /*
    * 竖向的panel
    */
    mao.ui.VerticalPanel = ecui.inherits(
        ui.MPanel,
        function (el, options) {
            ui.MPanel.call(this, el, options);
            this.verticalDrag = true;
        },
        {
            ondragstart: function (event) {
                if ((event.track.angle > 45 && event.track.angle < 135) || (event.track.angle > 225 && event.track.angle < 315)) {
                    this.verticalDrag = true;
                } else {
                    this.verticalDrag = false;
                }
            },
            $cache: function (style) {
                ui.MPanel.prototype.$cache.call(this, style);
                this.setScrollRange({
                    left: 0
                });
            },
            ondragend: function () {
                this.verticalDrag = true;
            },
            setPosition: function (x, y) {
                if (this.verticalDrag) {
                    ui.MPanel.prototype.setPosition.call(this, x, y);
                }
            },
            $draginertia: function (speed) {
                return Math.min(0.9, Math.abs(speed.y / 400));
            }
        }
    );
    /*
    * 横向的panel
    */
    mao.ui.HerizontalPanel = ecui.inherits(
        ui.MPanel,
        function (el, options) {
            ui.MPanel.call(this, el, options);
            this.herizontalDrag = true;
        },
        {
            ondragstart: function (event) {
                if ((event.track.angle > 45 && event.track.angle < 135) || (event.track.angle > 225 && event.track.angle < 315)) {
                    this.herizontalDrag = false;
                } else {
                    this.herizontalDrag = true;
                }
            },

            touchstart: function (event) {
                this.startPoint = { x : event.targetTouches[0].clientX, y: event.targetTouches[0].clientY };
                this.activateAngle = undefined;
            },
            touchmove: function (event) {
                if (this.activateAngle === undefined) {
                    var targetTouches = event.targetTouches[0];
                    this.activateAngle = calcAngle(targetTouches.clientX - this.startPoint.x, targetTouches.clientY - this.startPoint.y);
                }
                var angle = this.activateAngle;
                if (!((angle > 45 && angle < 135) || (angle > 225 && angle < 315))) {
                    event.preventDefault();
                }

            },
            touchend: function () {
                this.activateAngle = undefined;
                this.startPoint = {};
            },
            init: function () {
                dom.addEventListener(this.getMain(), 'touchstart', this.touchstart.bind(this));
                dom.addEventListener(this.getMain(), 'touchmove', this.touchmove.bind(this));
                dom.addEventListener(this.getMain(), 'touchend', this.touchend.bind(this));
                ecui.ui.MPanel.prototype.init.call(this);
            },
            $cache: function (style) {
                ecui.ui.MPanel.prototype.$cache.call(this, style);
                this.setScrollRange({
                    top: 0
                });
            },
            $dragmove: function (event) {
                ecui.ui.MPanel.prototype.$dragmove.call(this, event);
                if (this.herizontalDrag) {
                    event.preventDefault();
                }
            },
            ondragend: function (event) {
                this.herizontalDrag = true;
            },
            setPosition: function (x, y) {
                if (this.herizontalDrag) {
                    ecui.ui.MPanel.prototype.setPosition.call(this, x, y);
                }
            },
            $draginertia: function (speed) {
                return Math.min(0.7, Math.abs(speed.x / 400));
            }
        }
    );
    // 搜索栏
    mao.ui.SearchText = core.inherits(
        ecui.ui.Text,
        'ui-search-text',
        function (el, options) {
            ecui.ui.Text.call(this, el, options);

            var clear = ecui.dom.create({ className: 'ui-search-clear' });
            dom.insertAfter(clear, this.getInput());
            this._uClear = core.$fastCreate(this.Clear, clear, this, {});
            this._sListView = options.listView;
            this._bNotListView = options.notListView;
            this._sCont = options.cont;
        },
        {
            clearTimer: util.blank,
            Clear: core.inherits(
                ecui.ui.Control,
                {
                    onclick: function (event) {
                        this.getParent().setValue('');
                        ecui.dispatchEvent(this.getParent(), 'input');
                        event.preventDefault();
                        event.stopPropagation();
                    }
                }
            ),
            oninput: function () {
                this.clearTimer();
                this.clearTimer = util.timer(function () {
                    this.searchHandler();
                }, 300, this);
            },
            onkeydown: function (event) {
                if (event.which === 13) {
                    this.clearTimer();
                    this.searchHandler();
                    ecui.dispatchEvent(this, 'blur');
                    event.preventDefault();
                    event.stopPropagation();
                }
            },
            searchHandler: function () {
                if (this._bNotListView) {
                        
                    var cont = ecui.$(this._sCont),
                        value = this.getValue();

                    dom[value ? 'addClass' : 'removeClass'](cont, 'ui-searching');
                    dom.children(cont).forEach(function (item) {
                        if (item.getControl) {
                            var item = item.getControl();
                            if (item.getText().indexOf(value.trim()) > -1) {
                                item.alterStatus('-miss');
                            } else {
                                item.alterStatus('+miss');
                            }
                        }
                    });
                } else {
                    if (this._sListView && ecui.get(this._sListView)) {
                        ecui.dispatchEvent(ecui.get(this._sListView), 'refresh');
                    }
                }
            }
        }
    );

    mao.ui.ExpandBtn = ecui.inherits(
        ui.Control,
        'ui-expand-btn',
        function (el, options) {
            ui.Control.call(this, el, options);
            this._sCont = options.cont;
        },
        {
            onclick: function () {
                this._bExpand = !this._bExpand;
                this.expand();
            },
            onready: function () {
                util.timer(function () {
                    if (!this._eCont) {
                        this._eCont = ecui.$(this._sCont);
                        dom.children(this._eCont).forEach(function (item) {
                            dom.addClass(item, 'ui-expand-item');
                        });
                    }
                    if (dom.children(this._eCont).length <= 1) {
                        this.hide();
                        return;
                    }
                    dom.addClass(this._eCont, 'ui-expand-cont');
                    this._bExpand = false;
                    this.expand();
                }, 30, this);
            },
            expand: function () {
                dom[this._bExpand ? 'addClass' : 'removeClass'](this._eCont, 'expand');
                dom[this._bExpand ? 'addClass' : 'removeClass'](this.getMain(), 'expand');
                this.getMain().innerHTML = this._bExpand ? '收起' : '展开';
            }
        }
    );

    // 审批人员选择搜索框
    mao.ui.SearchApprovalPeopleText = ecui.inherits(
        mao.ui.SearchText,
        {
            searchHandler: function () {
                var panel = dom.next(dom.next(dom.parent(this.getMain()))),
                    value = this.getValue();
                dom[value ? 'addClass' : 'removeClass'](panel, 'ui-searching');
                this.searchTree(value);
            },

            searchTree: function (text) {
                var panel = dom.next(dom.next(dom.parent(this.getMain()))).getControl(),
                    tree = dom.first(dom.first(panel.getBody())).getControl(),
                    text = this.getValue();

                if (!tree) {
                    return;
                }
                function mapTree(tree) {
                    var viald;
                    var children = tree.getChildren();
                    if (children.length) {
                        var vialdArr = children.map(function (item) {
                            return mapTree(item);
                        });
                        viald = (vialdArr.indexOf(true) > -1);
                    } else {
                        viald = tree._oItem.name.indexOf(text.trim()) > -1;
                    }
                    if (viald) {
                        tree.alterStatus('-miss');
                    } else {
                        tree.alterStatus('+miss');
                    }
                    return viald;
                }
                mapTree(tree);
            }
        }
    );
    /**
     * 防止重复提交。
     * @public
     */
    ui.Submit = _interface('$Submit', {
        request: function (url, onsuccess, onerror) {
            if (this._bSend) {
                return;
            }
            this._bSend = true;
            mao.util.addLoading();
            ecui.esr.request(
                url,
                function () {
                    this.clearSend();
                    mao.util.removeLoading();
                    onsuccess.call(this);
                }.bind(this),
                function (err) {
                    this.clearSend();
                    mao.util.removeLoading();
                    if (onerror) {
                        onerror.call(this, err);
                    }
                    return false;
                }.bind(this)
            );
        },
        clearSend: function () {
            this._bSend = false;
        }
    });

    mao.ui.ShowImg = ecui.inherits(
        ecui.ui.Control,
        function (el, options) {
            ecui.ui.Control.call(this, el, options);
            this._sImg = options.img;
            this._sTitle = options.title;
        },
        {
            onclick: function (event) {
                ecui.esr.showSelect(ecui.esr.getEngine().render('show_img', {src: this._sImg}), function (event) {
                }, this._sTitle);
            }
        }
    );
    // 提供本项目tab切换使用的控件
    mao.ui.TabPanel = ecui.inherits(
        ecui.ui.MPanel,
        {
            ondragmove: function (event) {
                if (event.track && Math.abs(event.track.speedY) > Math.abs(event.track.speedX)) {
                    ecui.drag();
                    ecui.dispatchEvent(this.findControl(ecui.ui.Panel), 'activate', event);
                }
            }
        }
    );
    // 提供本项目tab切换使用的控件
    mao.ui.Tab = ecui.inherits(
        ecui.ui.Tab,
        function (el, options) {
            ecui.ui.Tab.call(this, el, options);
        },
        {
            onready: function () {
                this.getItems().forEach(function (item) {
                    item.value = {};
                    stableFormData(item);
                });

            },
            ontitleclick: function (event) {
                // 重置所有其它搜索栏选项
                this.getItems().forEach(function (item, index) {
                    if (index > 0) {
                        resetChecked(item);
                    }
                }.bind(this));

                if (this.getSelected() === event.item) {
                    this.setSelected(0);
                    return false;
                }
            },
            onconfirm: function (event) {
                if (event.showText) {
                    event.selected.getMain().getElementsByTagName('TABNAME')[0].innerHTML = event.text;
                }

                if (event.showNum && event.number !== undefined) {
                    event.selected.getMain().getElementsByTagName('STRONG')[0].innerHTML = event.number;
                }
                //ecui.dom.first(ecui.dom.first(event.selected.getMain())).innerHTML = event.text;
                ecui.dom[event.number ? 'addClass' : 'removeClass'](event.selected.getMain(), 'active');
            }
        }
    );

    mao.ui.PopupButton = ecui.inherits(
        ui.Control,
        'ui-layer-button',
        function (el, options) {
            ecui.ui.Control.call(this, el, options);
            var optionsEl = el.lastElementChild;
            var node = ecui.dom.create('div', {
                className: this.getClass() + '-popup ui-popup ui-hide ui-layer-popup'
            });
            optionsEl.className = ' ui-layer-popup-cont ' + optionsEl.className;
            node.appendChild(optionsEl);
            this._uPopup = ecui.$fastCreate(this.Popup, node, this, {focusable: false});
            this.setPopup(this._uPopup);
            this.$setBody(node);
            options.enter = 'bottom';
            options.mask = 0.5;
        },
        {
            Popup: ecui.inherits(
                ui.Control,
                function (el, options) {
                    ui.Control.call(this, el, options);

                    var close = ecui.dom.create('div', {
                        className: 'ui-popup-close'
                    });
                    el.appendChild(close);
                    ecui.$fastCreate(this.Close, close, this);
                },
                {
                    Close: ecui.inherits(
                        ui.Control,
                        {
                            $click: function () {
                                this.getParent().hide();
                            }
                        }
                    ),
                    $mousemove: function (event) {
                        ui.Control.prototype.$mousemove.call(this, event);
                        event.stopPropagation();
                    },
                    $activate: function (event) {
                        ui.Control.prototype.$activate.call(this, event);
                        event.stopPropagation();
                    },
                    $click: function (event) {
                        ui.Control.prototype.$click.call(this, event);
                        event.stopPropagation();
                    }
                }
            )
        },
        ui.MPopup
    );

    mao.ui.CostInvoiceAdd = ecui.inherits(
        mao.ui.PopupButton,
        'ui-cost-invoice-add',
        {
        }
    );

    /*
     * 路由切换tab 控件
     * @control
     */
    mao.ui.RouteTab = core.inherits(
        ui.Tab,
        {
            /**
             * 选项部件。
             * options 属性：
             * container   容器的id，如果通过这里设置，不允许改变关联容器
             * selected    当前项是否被选中
             * @unit
             */
            Item: core.inherits(
                ui.Tab.prototype.Item,
                function (el, options) {
                    ui.Tab.prototype.Item.call(this, el, options);
                    this._sRouteName = options.routeName;
                }
            ),
            onready: function () {
                this.onchange();
            },
            onchange: function () {
                var selected = this.getSelected(),
                    routeName = selected._sRouteName;
                if (typeof selected === 'number') {
                    routeName = this.getItem(Math.max(0, selected))._sRouteName;
                }
                if (routeName) {
                    delete ecui.esr.getRoute(routeName).CACHE;
                    ecui.esr.callRoute(routeName, true);
                }
            }
        }
    );

    mao.ui.NavTab = ecui.inherits(
        mao.ui.RouteTab,
        {
            onchange: function (event) {
                mao.ui.RouteTab.prototype.onchange.call(this, event);
                var selected = this.getSelected();
                var title = dom.last(selected.getMain()).innerText.trim();
                mao.util.setTitle(title);
                var header = this.findControl(ecui.esr.AppLayer).getMain().header;
                header.className = '';
                dom.addClass(header, 'show-' + this.getItems().indexOf(selected));
            }
        }
    );

    mao.ui.TabToggle = ecui.inherits(
        ui.Control,
        function (el, options) {
            ui.Control.call(this, el, options);
            this._sTab = +options.tab;
        },
        {
            onclick: function () {
                ecui.get('navTab').setSelected(this._sTab);
                ecui.dispatchEvent(ecui.get('navTab'), 'change');
            }
        }
    );
    // 重置tab搜索栏选项值
    function resetChecked(control) {
        if (!control.value) {
            control.value = {};
        }
        var inputs = control.getContainer().getElementsByTagName('INPUT');
        Array.prototype.slice.call(inputs).forEach(function (item) {
            if (item.getControl) {
                var subControl = item.getControl(),
                    value = control.value ? control.value[subControl.getName ? subControl.getName() : item.name] : '';
                if (!(subControl instanceof ecui.esr.CreateArray) && !(subControl instanceof ecui.esr.CreateObject) && subControl.setChecked && (subControl.getValue() === value || ((value === undefined || value === null) && subControl.getValue() === ''))) {
                    subControl.setChecked(true);
                }
            }
        });
    }
    // 头部导航栏 点击 返回 事件处理
    mao.ui.Back = ecui.inherits(
        ecui.ui.Control,
        function (el, options) {
            ecui.ui.Control.call(this, el, options);
        },
        {
            onclick: function () {
                window.history.go(-1);
            }
        }
    );

    // select 编辑项 控件
    /*
     * 点击打开弹框的 按钮，适用于  编辑信息、查看详情 弹窗打开按钮
     * options    属性：
     * view        展示选中项的模版view
     * sView       展示选中项的模版view
     * url         获取详情信息的接口路径
     * container   dialog容器id
     * target      dialog 的 内容target 模板名称
     *
     */
    mao.ui.SelectEdit = core.inherits(
        ecui.ui.InputControl,
        'ui-common-select',
        function (el, options) {
            ecui.ui.InputControl.call(this, el, options);
            this._bRequired = options.required;

            if (options.regexp) {
                this._oRegExp = new RegExp('^' + options.regexp + '$');
            }
            this._eInput = el.getElementsByTagName('INPUT')[0];
            dom.insertBefore(
                this._eText = dom.create({className: 'select-text'}),
                this._eInput
            );
            this._eInput.classList.add('ui-hide');

            if (options.items instanceof Object) {
                this._oItems = options.items;
            } else {
                this._oItems = JSON.parse(options.items || '[]');
            }
            this._bMutil = options.mutil;
            this._sView = options.view;
            this._sSView = options.sView;
            this._sTitle = options.title;
            this._sTip = options.tip;
            this._sPlaceholder = options.placeholder;
            this._oOptions = options;

            if (this._sSView) {
                if (options.data && JSON.stringify(options.data) !== '{}') {
                    this.setText(options.data);
                }
            } else {
                this.setText(options.text);
            }
        },
        {
            $click: function () {
                ecui.esr.showSelect(ecui.esr.getEngine().render(this._sView || (this._bMutil ? 'mutil_select' : 'single_select'), { 'items': this._oItems, value: this.getFormValue(), options: this._oOptions }), function (event) {
                    ecui.dispatchEvent(this, 'change', event);
                }.bind(this), { title: this._sTitle, weight: Number(this._oOptions.weight) || 10000 });
            },
            init: function () {
                ui.InputControl.prototype.init.call(this);
                this.alterStatus((this.getValue() === '' ? '+' : '-') + 'placeholder');
                dom[this.getValue() === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
                if (!this.getValue()) {
                    this.setPlaceholder();
                }
            },
            onchange: function (event) {
                this.setSelected(event);
                this.alterStatus((this.getValue() === '' ? '+' : '-') + 'placeholder');
                dom[this.getValue() === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
                if (!this.getValue()) {
                    this.setPlaceholder();
                }
            },
            onclear: function () {
                this.setValue('');
                ecui.dispose(this._eText, true);
                this._eText.innerHTML = '';
                this.alterStatus('+placeholder');
                dom.addClass(this.getMain(), 'placeholder');
            },
            setSelected: function (event) {
                var item = event.item;
                var text = '';
                if (item instanceof Array) {
                    this.getInput().value = event.item.map(function (item) { return item._sValue || item.id || item.value; }).join(',');
                    text = event.item.map(function (item) { return item._sText || item.text || item.name; }).join(',');
                } else {
                    this.getInput().value = item._sValue || item.id || item.value;
                    text = item._sText || item.text || item.name;
                }
                if (this._sSView) {
                    this.setText(item);
                } else {
                    this.setText(text);
                }
            },
            getText: function () {
                return this._eText.innerHTML;
            },
            getFormValue: function () {
                var value = this.getValue();
                return this._bMutil ? (value ? value.split(',') : []) : value;
            },
            setValue: function (e) {
                if (typeof e === 'object') {
                    this._eText.innerHTML = e.salesName;
                    this._eInput.value = e.salesId;
                } else {
                    for (var i = 0, length = this._oItems.length; i < length; i++) {
                        if (String(this._oItems[i].id) === String(e)) {
                            this._eText.innerHTML = this._oItems[i].text || this._oItems[i].name;
                        }
                    }
                    if (e && (!this._eText.innerHTML || this._eText.innerHTML === '请选择') && e !== '-1' && e !== '0') {
                        this._eText.innerHTML = e;
                    }
                    ecui.ui.InputControl.prototype.setValue.call(this, e);
                }
                this.alterStatus((this.getValue() === '' ? '+' : '-') + 'placeholder');
                dom[this.getValue() === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
            },
            setText: function (text) {
                if (!text) {
                    this.setPlaceholder();
                    return;
                }
                if (this._sSView) {
                    var item = text;
                    text = ecui.esr.getEngine().render(this._sSView, Object.assign({ selected: true }, item instanceof Array ? { items: item } : { item: item }));
                    ecui.dispose(this._eText, true);
                    this._eText.innerHTML = text;
                    ecui.init(this._eText);
                } else {
                    this._eText.innerHTML = text;
                }
            },
            setPlaceholder: function () {
                this._eText.innerHTML = this._sPlaceholder || '请选择' + this._sTitle;
            },
            $validate: function () {
                ecui.ui.InputControl.prototype.$validate.call(this);
                var value = this.getFormValue(),
                    result = true;

                if (this._bTrim) {
                    value = value.trim();
                }
                if (this._bRequired) {
                    if (value instanceof Array && !value.length) {
                        result = false;
                    } else if (!value) {
                        result = false;
                    }
                }
                if ((this._oRegExp && !this._oRegExp.test(value)) || (isNaN(+value) && (this._nMinValue !== undefined || this._nMaxValue !== undefined))) {
                    result = false;
                }

                if (!result) {
                    core.dispatchEvent(this, 'error');
                }
                return result;
            },
            onerror: function () {
                ecui.tip('warn', '请选择' + this._sTitle);
            }
        }
    );

    // 部门人员单选、多选页面
    mao.ui.MutilPeopleSelect = core.inherits(
        ui.Control,
        function (el, options) {
            ui.Control.call(this, el, options);
            this._bIsDept = !!options.isDept;
            this._bMutil = !!options.mutil;
            this._oSourceTree = this._bIsDept ? mao.info.deptTree : mao.info.staffTree;

            // 遍历搜索用户列表
            var items = [];
            var itemsMap = {};
            mao.util.mapTree(this._oSourceTree[0], function (item) {
                var flag = this._bIsDept ? item.type === 1 : item.type === 2;
                if (flag) {
                    items.push(Object.assign({}, item, { children: [] }));
                    itemsMap[item.id] = Object.assign({}, item, { children: [] });
                }
            }.bind(this));
            this.searchlist = items;
            this.searchlistMap = items;

            // 初始化部件
            var children = dom.children(el);
            this._uSearch = core.$fastCreate(this.SearchText, dom.first(children[0]), this, {});
            this._uChooseText = core.$fastCreate(this.ChooseText, children[1], this, {});
            dom.addClass(this._uSearch.getMain(), ' ui-search-text ui-text ui-input ');

            this._oItems = [];
            if (this._bMutil) {
                this._uList = core.$fastCreate(this.MutilList, children[2], this, {});
                el = dom.last(el);
                this._uResult = core.$fastCreate(this.Result, dom.first(el), this, {});
                this._uSubmit = core.$fastCreate(this.Submit, dom.last(el), this, {});

                var ids = options.value ? options.value.split(',') : [];
                this._oItems = ids.map(function (item) { return itemsMap[item]; });
                this._uResult.setText();
                this.refreshList(undefined, true);
            } else {
              this._uList = core.$fastCreate(this.List, children[2], this, {});
              this.refreshList(options.value, true);
            }
        },
        {
            searchlist: [],
            max: 50,
            // 单选人员列表
            List: core.inherits(
                ui.Control,
                {
                    TEXTNAME: 'name',
                    Item: core.inherits(
                        ui.Item,
                        function (el, options) {
                            ui.Item.call(this, el, options);
                            el.appendChild(dom.create({ className: 'icon', innerHTML: '下级' }));
                            this._sValue = options.id;
                            this._oItem = Object.assign({}, options, { parent: undefined, primary: undefined, uid: undefined });
                            dom.addClass(el, 'children-' + (options.children.length || 0));
                        },
                        {
                            onclick: function (event) {
                                var uList = this.getParent(),
                                    parent = uList.getParent();
                                uList.setSelected(this);
                                if (parent._bIsDept) {
                                    // 部门选择
                                    if (dom.hasClass(event.target, 'icon')) {
                                        uList.getParent().refreshList(this._sValue);
                                    } else {
                                        ecui.dispatchEvent(parent, 'change', { item: this._oItem });
                                    }
                                } else {
                                    // 人员选择
                                    if (this._oItem.type === 2) {
                                        ecui.dispatchEvent(parent, 'change', { item: this._oItem });
                                    } else {
                                        uList.getParent().refreshList(this._sValue);
                                    }
                                }

                            }
                        }
                    ),
                    $alterItems: util.blank
                },
                ui.Items,
                ui.Control.defineProperty('selected')
            ),
            // 多选人员列表
            MutilList: core.inherits(
                ui.Control,
                {
                    TEXTNAME: 'name',
                    Item: core.inherits(
                        ui.Item,
                        function (el, options) {
                            ui.Item.call(this, el, options);
                            el.appendChild(dom.create({ className: 'icon', innerHTML: '下级' }));
                            this._bAll = options.all;
                            this._bSelected = options.selected;
                            this._sValue = options.id;
                            this._oItem = Object.assign({}, options, { parent: undefined, primary: undefined, uid: undefined });

                            this.alterStatus(this._bSelected ? '+selected' : '-selected');
                            dom.addClass(el, 'children-' + (options.children.length || 0) +(options.all ? ' all' : ''));
                        },
                        {
                            onclick: function (event) {
                                this._bSelected = !this._bSelected;
                                this.alterStatus(this._bSelected ? '+selected' : '-selected');
                                var parent = this.getParent().getParent();
                                // 全选按钮
                                if (this._bAll) {
                                    // 设置选中效果
                                    parent._uList.getItems().forEach(function (item, index) {
                                        if (item !== this) {
                                            item._bSelected = this._bSelected;
                                            item.alterStatus(this._bSelected ? '+selected' : '-selected');
                                        }
                                    }.bind(this));
                                    // 设置选中结果
                                    var data = parent._oData[parent._oData.length - 1] || parent._oSourceTree[0];
                                    var items = [];
                                    mao.util.mapTree(data, function (item) {
                                        if (item.type === 2) {
                                            items.push(Object.assign({}, item, { children: [] }));
                                        }
                                    });
                                    ecui.dispatchEvent(parent, 'change', { all: true, item: items, selected: this._bSelected });
                                    return;
                                }
                                var uList = this.getParent();
                                if (dom.hasClass(event.target, 'icon')) {
                                    // 点击下级按钮
                                    uList.getParent().refreshList(this._sValue);
                                } else {
                                    // 选择人
                                    if (this._oItem.type === 2) {
                                        ecui.dispatchEvent(uList.getParent(), 'change', { item: this._oItem, selected: this._bSelected });
                                    } else {
                                        // 点击部门，选择部门下的所有人
                                        var items = [];
                                        mao.util.mapTree(this._oItem, function (item) {
                                            if (item.type === 2) {
                                                items.push(Object.assign({}, item, { children: [] }));
                                            }
                                        });
                                        ecui.dispatchEvent(parent, 'change', { all: true, item: items, selected: this._bSelected });
                                    }
                                }
                            }
                        }
                    ),
                    $alterItems: util.blank
                },
                ui.Items
            ),
            // 搜索框
            SearchText: core.inherits(
                mao.ui.SearchText,
                {
                    searchHandler: function () {
                        var parent = this.getParent(),
                            value = this.getValue();
                        dom[value ? 'addClass' : 'removeClass'](parent.getMain(), 'ui-searching');
                        if (value) {
                            this.searchTree(value);
                        } else {
                            var data = parent._oData[parent._oData.length - 1] || {};
                            parent.refreshList(data.id);
                        }
                    },

                    searchTree: function (text) {
                        var parent = this.getParent(),
                            uList = parent._uList,
                            text = this.getValue().trim(),
                            ids = parent._oItems.map(function (item) { return item.id; });

                        var searchlist = parent.searchlist.filter(function (item) {
                            return item.name.indexOf(text) >= 0;
                        });
                        searchlist = [].concat(searchlist);
                        searchlist.forEach(function (item) {
                            item.selected = (ids.indexOf(item.id) >= 0)
                        });
                        uList.removeAll(true);
                        uList.add(searchlist);
                    }
                }
            ),
            // 当前选中节点文案
            ChooseText: core.inherits(
                ui.Control,
                {
                    onclick: function (event) {
                        var parent = this.getParent();
                        var index = dom.children(this.getMain()).indexOf(event.target);
                        if (index % 2 === 0) {
                            if (index === 0) {
                                parent.refreshList();
                            } else {
                                parent.refreshList(parent._oData[index / 2 - 1].id);
                            }
                        }
                    }
                }
            ),
            // 底部结果展示
            Result: core.inherits(
                ui.Control,
                function (el, options) {
                    ui.Control.call(this, el, options);

                    var popupEl = dom.create('div', {
                        className: 'ui-popup ui-hide ui-people-result-popup',
                        innerHTML: '<div class="popup-title"><div class="label">已选择5人</div><div class="confirm">确定</div></div><div class="people-list"></div>'
                    });
                    this._uPopup = core.$fastCreate(this.Popup, popupEl, this, {focusable: false});
                    this.setPopup(this._uPopup);
                    this.$setBody(popupEl);
                    options.enter = 'bottom';
                    options.mask = 0.5;
                },
                {
                    Popup: core.inherits(
                        ui.Control,
                        function (el, options) {
                            ui.Control.call(this, el, options);
                            
                            this._uConfirm = core.$fastCreate(this.Confirm, dom.last(dom.first(el)), this);
                            this._uList = core.$fastCreate(this.List, dom.last(el), this);
                        },
                        {
                            List: core.inherits(
                                ui.MPanel,
                                {
                                    Item: core.inherits(
                                        ui.Item,
                                        function (el, options) {
                                            ui.Item.call(this, el, options);
                                            el.appendChild(dom.create({ className: 'icon' }));
                                            el.appendChild(dom.create({ className: 'name', innerHTML: options.name }));
                                            el.appendChild(dom.create({ className: 'close', innerHTML: '移除' }));
                                            this._oItem = Object.assign({}, options, { parent: undefined, primary: undefined, uid: undefined });
                                            this._uClose = core.$fastCreate(this.Close, dom.last(el), this);
                                        },
                                        {
                                            Close: core.inherits(
                                                ui.Control,
                                                {
                                                    onclick: function (event) {
                                                        var parent = this.getParent();
                                                        event.item = parent;
                                                        ecui.dispatchEvent(parent.getParent(), 'itemchange', event);
                                                        event.stopPropagation();
                                                    }
                                                }
                                            )
                                        }
                                    ),
                                    onitemchange: function (event) {
                                        var parent = this.getParent().getParent().getParent();
                                        var oItem = event.item._oItem;
                                        util.timer(function () {
                                            this.remove(event.item);
                                            parent._uList.getItems().forEach(function (item) {
                                                if (item._oItem.id === oItem.id || !parent.isCheckedAll(item._oItem)) {
                                                    item._bSelected = false;
                                                    item.alterStatus('-selected');
                                                }
                                            });
                                            ecui.dispatchEvent(parent, 'change', { item: oItem, selected: false, isRemove: true });
                                        }, 30, this);
                                    },
                                    $alterItems: util.blank
                                },
                                ui.Items
                            ),
                            Confirm: core.inherits(
                                ui.Control,
                                {
                                    $click: function () {
                                        this.getParent().hide();
                                        var parent = this.getParent().getParent().getParent();
                                        core.dispatchEvent(parent.getParent(), 'confirm', { items: parent._oItems });
                                    }
                                }
                            ),
                            $mousemove: function (event) {
                                ui.Control.prototype.$mousemove.call(this, event);
                                event.stopPropagation();
                            },
                            $activate: function (event) {
                                ui.Control.prototype.$activate.call(this, event);
                                event.stopPropagation();
                            },
                            $click: function (event) {
                                ui.Control.prototype.$click.call(this, event);
                                event.stopPropagation();
                            },
                            show: function () {
                                ui.Control.prototype.show.call(this);
                                var parent = this.getParent().getParent();
                                this._uList.removeAll(true);
                                this._uList.add(parent._oItems);
                            },
                            hide: function () {
                                ecui.ui.Control.prototype.hide.call(this);
                            }
                        }
                    ),
                    setText: function () {
                        var parent = this.getParent();
                        this.getMain().innerHTML = parent._oItems.length ? util.stringFormat(
                            '<div class="label">已选择:{1}人</div><div class="res">{0}</div>',
                            parent._oItems.map(function (item) { return item.name; }).reverse().join(','),
                            parent._oItems.length
                        ) : util.stringFormat('<div class="placeholder">最多选择{0}人</div>', parent.max);
                    }
                },
                ui.MPopup
            ),
            // 底部确定按钮
            Submit: core.inherits(
                ui.Button,
                {
                    onclick: function () {
                        ecui.dispatchEvent(this.getParent().getParent(), 'confirm', { items: this.getParent()._oItems });
                    }
                }
            ),
            findDept: function (id) {
                return mao.util.findTree(this._oSourceTree[0], id);
            },
            refreshList: function (id, isInit) {
                var data = this.findDept(id);
                this._oData = data;
                if (data.length) {
                    var lsatData = data[data.length - 1];
                    if (isInit || (!lsatData.children || !lsatData.children.length)) {
                        lsatData = data[data.length - 2];
                    }
                    this._uList.removeAll(true);
                    if (lsatData) {
                        this._uList.add(this.mapData(lsatData.children));
                    } else {
                        this._uList.add(this.mapData(this._oSourceTree));
                    }
                    if (!this._bMutil) {
                        this._uList.setSelected(this._uList.getItems().find(function (item) {
                            return item._sValue === id;
                        }));
                    }
                } else {
                    this._uList.removeAll(true);
                    this._uList.add(this.mapData(this._oSourceTree));
                }
                var text = ['通讯录'];
                data.forEach(function (item) {
                    text.push(item.name);
                });
                this._uChooseText.getMain().innerHTML = text.map(function (item, index) {
                    return util.stringFormat('<span {1}>{0}</span>', item, index === text.length - 1 ? '' : 'class="primary-text"');
                }).join('<span> > </span>');
            },
            findItem: function (id) {
                var index = -1;
                this._oItems.forEach(function (item, i) {
                    if (item.id === id) {
                        index = i;
                    }
                });
                return index;
            },
            /*
             * item        选项数据
             */
            isCheckedAll: function (item) {
                var checkAll = true;
                    ids = this._oItems.map(function (item) { return item.id; });

                if (item.children === undefined) {
                    item = this.findDept(id).pop();
                }
                mao.util.mapTree(item, function (tree) {
                    if (tree.type === 2 && ids.indexOf(tree.id) < 0) {
                        checkAll = false;
                    }
                });
                return checkAll;
            },
            mutilSelectedItem: function (item, isSelected) {
                var index = this.findItem(item.id);
                if (isSelected) {
                    if (index < 0) {
                        this._oItems.push(item);
                    }
                } else {
                    if (index >= 0) {
                        this._oItems.splice(index, 1);
                    }
                }
            },
            onchange: function (event) {
                if (this._bMutil) {
                    // 多选
                    if (event.all) {
                        // 全选
                        (event.item || []).forEach(function (item) {
                            if (item.type === 2) {
                                this.mutilSelectedItem(item, event.selected);
                            }
                        }.bind(this));
                    } else {
                        // 单选
                        this.mutilSelectedItem(event.item, event.selected);
                    }
                    this._uResult.setText();
                } else {
                    core.dispatchEvent(this.getParent(), 'confirm', { items: [event.item] });
                }
            },
            setSelected: function () {
                ecui.dispatchEvent(this.getParent(), 'confirm', { data: this._oData });
            },
            mapData: function (data) {
                var me = this;
                var ids = this._oItems.map(function (item) { return item.id; });
                var _data = data.map(function (item) {
                    return Object.assign({}, item, {
                        name: item.children.length ? item.name + ' (' + (me._bIsDept ? item.dCount : item.sCount) + ')' : item.name,
                        selected: (ids.indexOf(item.id) >= 0 || me.isCheckedAll(item))
                    })
                });
                if (this._bMutil) {
                    _data.unshift({ name: '全部', all: true, children: [] });
                }
                return _data;
            }
        }
    );
    // 部门、人员单选
    mao.ui.ChooseDeptStaff = core.inherits(
        mao.ui.SelectEdit,
        function (el, options) {
            mao.ui.SelectEdit.call(this, el, options);
            this._sView = 'mutil_dept_staff_select';
        },
        {
            setSelected: function (event) {
                var items = event.items || [];
                var item = items[items.length - 1] || {};
                // this._eText.innerHTML = items.map(function (item) { return item.name }).join(' - ');
                this._eText.innerHTML = item.name;
                this._eInput.value = item.id;
                this.alterStatus((this._eInput.value === '' ? '+' : '-') + 'placeholder');
            }
        }
    );

    // 人员选择多选控件
    mao.ui.Pople = core.inherits(
        ecui.ui.InputControl,
        function (el, options) {
            ecui.ui.InputControl.call(this, el, options);
            this._sName = options.name;
            this._sTitle = options.title;
            this._sLabelFormat = options.labelFormat || '';
            this._bRequired = options.required;
            this._bMutil = options.mutil;
            this._sView = options.view || 'mutil_dept_staff_select';

            this._uLabel = core.$fastCreate(this.Label, dom.children(el)[1], this);
            this._uPeoples = core.$fastCreate(this.Peoples, dom.children(el)[2], this);
            this._uAdd = core.$fastCreate(this.Add, dom.last(el), this);
            this._uLabel.setText();

            if (options.data instanceof Array) {
                this._uPeoples.add(options.data.map(function (item) {
                    return { 'value': item.id, 'name': item.name };
                }));
                this.changeHandler();
            } else {
                this.changeHandler();
            }
        },
        {
            Label: core.inherits(
                ui.Control,
                {
                    setText: function () {
                        var parent = this.getParent(),
                            peopleLength = parent._uPeoples._aChildren.length;
                        dom.last(this.getMain()).innerHTML = peopleLength ? util.stringFormat(parent._sLabelFormat, peopleLength) : '请选择' + parent._sTitle;
                    }
                }
            ),
            Peoples: core.inherits(
                ui.MPanel,
                function (el, options) {
                    ecui.ui.MPanel.call(this, el, options);
                    this._aChildren = [];
                },
                {
                    People: core.inherits(
                        ui.Control,
                        function (el, options) {
                            dom.addClass(el, 'people-item');
                            if (options.headPortrait) {
                                el.innerHTML = util.stringFormat('<img src="{0}" /><span class="name">{1}</span><span class="close"></span>', options.headPortrait, options.name);
                            } else {
                                el.innerHTML = util.stringFormat('<div class="head">{0}</div><span class="name">{1}</span><span class="close"></span>', options.name.slice(0, 1), options.name);
                            }
                            this._sValue = options.value;
                            this._sData = { 'headPortrait': options.headPortrait, 'name': options.name, 'value': options.value };
                            ui.Control.call(this, el, options);

                            this._uClose = core.$fastCreate(this.Close, dom.last(el), this, options);
                        },
                        {
                            Close: core.inherits(
                                ui.Control,
                                {
                                    onclick: function (event) {
                                        var parent = this.getParent().getParent().getParent();
                                        this.getParent().remove();
                                        ecui.dispatchEvent(parent, 'change', event);
                                    }
                                }
                            ),
                            remove: function () {
                                var parent = this.getParent(),
                                    main = this.getMain();

                                parent._aChildren.splice(parent._aChildren.indexOf(this), 1);
                                this.dispose();
                                main.remove();
                            },
                            getData: function () {
                                return this._sData;
                            }
                        }
                    ),
                    removeAll: function () {
                        this._aChildren.forEach(function (item) {
                            var main = item.getMain();

                            item.dispose();
                            main.remove();
                        });
                        this._aChildren = [];
                    },
                    add: function (data) {
                        if (!(data instanceof Array)) {
                            data = [data];
                        }
                        data.forEach(function (item) {
                            var people;
                            this._aChildren.push(people = core.$fastCreate(this.People, dom.create('LI'), this, Object.assign({}, item)));
                            dom.first(this.getMain()).appendChild(people.getMain());
                        }.bind(this));
                    },
                    getChildrens: function () {
                        return this._aChildren;
                    }
                }
            ),
            Add: core.inherits(
                ui.Control,
                {
                    onclick: function () {
                        var parent = this.getParent(),
                            uPeoples = parent.getPeoples(),
                            ids = uPeoples._aChildren.map(function (item) { return item._sData.value });

                        ecui.esr.showSelect(ecui.esr.getEngine().render(parent._sView, { mutil: parent._bMutil, value: ids }), function (event) {
                            ecui.dispatchEvent(parent, 'confirm', event);
                            if (parent.getBody().classList.value.indexOf('placeholder') !== -1) {
                                ecui.dom.removeClass(this.getBody(), 'placeholder');
                            }
                        }.bind(this), parent._sTitle);
                    }
                }
            ),
            $validate: function () {
                ui.InputControl.prototype.$validate.call(this);
                var value = this.getFormValue(),
                    result = true;

                if (this._bRequired && !value.length) {
                    result = false;
                }

                if (!result) {
                    core.dispatchEvent(this, 'error');
                }
                return result;
            },
            onconfirm: function (event) {
                var uPeoples = this._uPeoples;
                uPeoples.removeAll();
                uPeoples.add(event.items.map(function (item) {
                    var data = item._oItem;
                    return { 'value': item.id, 'name': item.name };
                }));
                ecui.dispatchEvent(this, 'change', event);
            },
            onchange: function () {
                this.changeHandler();
            },
            changeHandler: function () {
                this._uLabel.setText();
                this.getInput().value = this._uPeoples._aChildren.map(function (item) { return item._sValue; }).join(',');

                dom[!this.getFormValue().length ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
            },
            getFormValue: function () {
                var value = this.getValue();
                return value ? value.split(',') : [];
            },
            getPeoples: function () {
                return this._uPeoples;
            }
        }
    );
    // select 编辑项 跳转路由选择 控件
    mao.ui.SelectRoute = core.inherits(
        ecui.ui.InputControl,
        'ui-common-select',
        function (el, options) {
            ecui.ui.InputControl.call(this, el, options);

            this._bRequired = options.required;
            this._bMutil = options.mutil;
            if (options.regexp) {
                this._oRegExp = new RegExp('^' + options.regexp + '$');
            }
            this._eInput = el.getElementsByTagName('INPUT')[0];
            dom.insertBefore(
                this._eText = dom.create({className: 'select-text'}),
                this._eInput
            );
            this._eInput.classList.add('ui-hide');
            this._eText.innerHTML = options.text;
            this._sTitle = options.title;
            this._sSView = options.sView;
            this._sRoute = options.route;
            this._sTip = options.tip;

            if (this._sSView) {
                if (options.data && JSON.stringify(options.data) !== '{}') {
                    this.setText(options.data);
                }
            } else {
                this.setText(options.text);
            }
        },
        {
            $validate: function () {
                ecui.ui.InputControl.prototype.$validate.call(this);
                var value = this.getFormValue(),
                    result = true;

                if (this._bTrim) {
                    value = value.trim();
                }
                if (this._bRequired) {
                    if (value instanceof Array && !value.length) {
                        result = false;
                    } else if (!value) {
                        result = false;
                    }
                }
                if ((this._oRegExp && !this._oRegExp.test(value)) || (isNaN(+value) && (this._nMinValue !== undefined || this._nMaxValue !== undefined))) {
                    result = false;
                }

                if (!result) {
                    core.dispatchEvent(this, 'error');
                }
                return result;
            },
            init: function () {
                ui.InputControl.prototype.init.call(this);
                this.alterStatus((this.getValue() === '' ? '+' : '-') + 'placeholder');
                dom[this.getValue() === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
                // if (!this.getValue()) {
                //     this._eText.innerHTML = '请选择' + this._sTitle;
                // }
            },
            onclick: function () {
                ecui.esr.findRoute(this).notleave = false;
                ecui.esr.redirect(this._sRoute);
                var route = ecui.esr.getRoute(this._sRoute.split('~')[0]);
                route.owner = this;
            },
            onchange: function (event) {
                this.setSelected(event);
                this.alterStatus((this.getValue() === '' ? '+' : '-') + 'placeholder');
                dom[this.getValue() === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
            },
            onclear: function () {
                this.setValue('');
                ecui.dispose(this._eText, true);
                this._eText.innerHTML = '';
                this.alterStatus('+placeholder');
                dom.addClass(this.getMain(), 'placeholder');
            },
            setSelected: function (event) {
                var item = event.item;
                var text = '';
                if (item instanceof Array) {
                    this.getInput().value = event.item.map(function (item) { return item._sValue || item.id || item.value; }).join(',');
                    text = event.item.map(function (item) { return item._sText || item.text || item.name; }).join(',');
                } else {
                    this.getInput().value = item._sValue || item.id || item.value;
                    text = item._sText || item.text || item.name;
                }
                if (this._sSView) {
                    this.setText(item);
                } else {
                    this.setText(text);
                }
            },
            getFormValue: function () {
                var value = this.getValue();
                return this._bMutil ? (value ? value.split(',') : []) : value;
            },
            getText: function () {
                return this._eText.innerHTML;
            },
            setText: function (text) {
                if (this._sSView) {
                    var item = text;
                    text = ecui.esr.getEngine().render(this._sSView, item instanceof Array ? { items: item } : { item: item });
                    ecui.dispose(this._eText, true);
                    this._eText.innerHTML = text;
                    ecui.init(this._eText);
                } else {
                    this._eText.innerHTML = text;
                }
            }
        }
    );
    mao.ui.TreeView = ecui.inherits(
        ui.TreeView,
        function (el, options) {
            ui.TreeView.call(this, el, options);
            this._oItem = options.item;
            this._sValue = options.value;
            this._sName = options.name;
        }
    );
    /*
     * 上传图片控件
     * options    属性：
     *      sourceType        h5调用手机选择图片形式，默认值是all， all: 相机、相册选择， camera: 相机， album: 相册
     *      defaultImg       按钮默认展示图片
     * url         获取详情信息的接口路径
     * container   dialog容器id
     * target      dialog 的 内容target 模板名称
     *
     */
    mao.ui.ImageAdd = core.inherits(
        ecui.ui.Upload,
        'ui-image-add',
        function (el, options) {
            options.url = '/erp-management/file/upload';
            ecui.ui.Upload.call(this, el, options);
            // accept="image/*"
            var inputs = el.getElementsByTagName('INPUT');
            var imgs = el.getElementsByTagName('IMG');
            this._eFile =inputs[0];
            this._eInput = inputs[1];
            this._eImg = imgs[0];
            this._sSourceType = options.sourceType || 'all';
            this._sDefaultImg = options.defaultImg || 'images/order/add_gray.png';
        },
        {
            onbeforeUpload: function () {
                this.alterStatus('+loading');
                this._eFile.name = 'file';
            },
            onclick: function (event) {
                if (mao.info.ddReady && event.target.tagName !== 'INPUT') {
                    var sourceType = ['camera', 'album'];
                    var parent = this.getParent();
                    var isPopupButton = parent && parent.getParent && parent.getParent() ? parent.getParent() instanceof mao.ui.PopupButton : false;
                    // 关闭弹层
                    if (isPopupButton) {
                        parent.hide();
                    }
                    // 处理打开相机类型
                    if (this._sSourceType !== 'all') {
                        sourceType = [this._sSourceType];
                    }
                    mao.util.chooseImage({
                        sourceType: sourceType,
                        onSuccess: function (res) {
                            this.onupload(res);
                            mao.util.removeLoading();
                        }.bind(this),
                        onFail: function(err) {
                            this.onerror(err);
                            mao.util.removeLoading();
                        }.bind(this)
                    });
                }
            },
            onupload: function (res) {
                this.alterStatus('-loading');
                this._eFile.name = '';
                this._eFile.value = ''; // 解决连续操作上传删除同一张图片时，第二次上传失败问题
                try {
                    res = JSON.parse(res);
                } catch (error) {}
                if (res.code === 0) { // 显示上传的图片
                    ecui.dispatchEvent(this, 'success', { item: res.data });
                } else if (res.code === 12020) {
                    ecui.tip('warn', '最大支持10m图片，请重新选择');
                }
            },
            onsuccess: function (event) {
                this._eImg.src = event.item.imageUrl || this._sDefaultImg;
                this._eInput.value = event.item.id;
            },
            onerror: function (err) {
                this.alterStatus('-loading');
                this._eFile.name = '';
                this._eFile.value = '';
            },
            getInputEl: function () {
                return this._eInput;
            }
        }
    );
    
    // 上传发票
    mao.ui.CostInvoiceUpload = ecui.inherits(
        mao.ui.ImageAdd,
        function (el, options) {
            mao.ui.ImageAdd.call(this, el, options);
            this._bFromBill = options.fromBill;
            this._sUrl = '/erp-management/file/upload/file';
        },
        {
            onupload: function (data, imgName, name) {
                if (typeof data === 'string') {
                    data = JSON.parse(data);
                }
                this._eFile.value = '';
                if (data.code === 0) {
                    mao.util.addLoading();
                    ecui.esr.request(
                        'invoiceData@JSON /erp-management/expense/identification/invoice/upload/' + data.data.id,
                        function () {
                            var code = ecui.esr.getData('invoiceData_CODE');
                            var data = ecui.esr.getData('invoiceData');
                            mao.util.removeLoading();
                            if (code === 0) {
                                ecui.dispatchEvent(this, 'success', { data: data });
                            }
                        }.bind(this),
                        function () {
                            mao.util.removeLoading();
                            return false;
                        }.bind(this)
                    );
                } 
            },
            onerror: function () {
                this._eFile.value = '';
            },
            onsuccess: function (event) {
                console.log(event.data);
                if (this._bFromBill) {
                    mao.info.invoiceInfo = event.data;
                    ecui.esr.redirect('/finance/book.edit~fromBill~DENY_CACHE');
                } else {
                    event.data.forEach(function (item) {
                        var el = dom.create({ innerHTML: ecui.esr.getEngine().render('invoiceItem', { item: item }) })
                        var uList = dom.previous(this.getParent().getParent().getMain()).getControl();
                        uList.add(dom.last(el));
                    }.bind(this));
                }
                this.getParent().hide();
            }
        }
    );
    // 发票项编辑
    mao.ui.InvoiceSelectRoute = ecui.inherits(
        mao.ui.SelectRoute,
        {
            setSelected: function (event) {
                var item = event.item;
                this.getInput().value = item.id;
                dom.children(this.getMain())[1].innerHTML = ecui.esr.getEngine().render('invoiceInfo', { item: item });
            }
        }
    )
    // 上传文件
    mao.ui.Files = core.inherits(
        ui.InputControl,
        function (el, options) {
            ecui.ui.InputControl.call(this, el, options);
            this._sName = options.name;
            this._bRequired = options.required;

            this._uFiles = core.$fastCreate(this.Files, dom.children(el)[1], this);
            this._uAdd = core.$fastCreate(this.AddFile, dom.last(el), this);

            if (options.data instanceof Array) {
                this._uFiles.add(options.data);
                this.refreshValue();
            }
        },
        {
            Files: core.inherits(
                ui.MListView,
                {
                    Item: core.inherits(
                        mao.ui.ImageAdd,
                        function (el, options) {
                            dom.addClass(el, 'ui-upload');
                            el.innerHTML = '<input name="file" data-name="file" type="file" class="file"/><div class="img-cont"><img src="' + options.imageUrl + '"/></div><span class="close"></span>';
                            var item = Object.assign({}, options, { parent: undefined, primary: undefined, uid: undefined });
                            mao.ui.ImageAdd.call(this, el, options);
                            this._oItem = Object.assign({}, item);
                            // this._oItem.id = item.id || item.value;
                            this._eImg.onload = this.fillImg.bind(this);
                            core.$fastCreate(this.Close, dom.last(el), this);
                        },
                        {
                            Close: core.inherits(
                                ui.Control,
                                {
                                    onclick: function () {
                                        var parent = this.getParent(),
                                            uFiles = parent.getParent();

                                        uFiles.remove(parent);
                                        ecui.dispatchEvent(uFiles.getParent(), 'change');
                                    }
                                }
                            ),
                            /**
                             * 图片完成填充div。
                             * @public
                             *
                             */
                            fillImg: function () {
                                var w = this.getWidth(),
                                    h = this.getHeight(),
                                    w_img = this._eImg.width,
                                    h_img = this._eImg.height;
                
                                this._eImg.style.position = 'relative';
                                if (w_img / h_img > w / h) {
                                    var left = (h * w_img / h_img - w) / 2;
                                    this._eImg.style.width = 'auto';
                                    this._eImg.style.height = '100%';
                                    this._eImg.style.left = -(left || 0) + 'px';
                                } else {
                                    var top = (w * h_img / w_img - h) / 2;
                                    this._eImg.style.width = '100%';
                                    this._eImg.style.height = 'auto';
                                    this._eImg.style.top = -(top || 0) + 'px';
                                }
                            },
                            onsuccess: function (event) {
                                this._eImg.src = event.item.imageUrl;
                                this._oItem = event.item.data;
                                ecui.dispatchEvent(this.getParent().getParent(), 'change');
                            }
                        }
                    )
                }
            ),
            AddFile: core.inherits(
                mao.ui.ImageAdd,
                function (el, options) {
                    dom.addClass(el, 'ui-upload');
                    el.innerHTML = '<input name="file" data-name="file" type="file" class="file" /><img/>';
                    mao.ui.ImageAdd.call(this, el, options);
                },
                {
                    onsuccess: function (event) {
                        this.getParent()._uFiles.add(event.item);
                        ecui.dispatchEvent(this.getParent(), 'change');
                    }
                }
            ),
            $validate: function () {
                ui.InputControl.prototype.$validate.call(this);
                var value = this.getFormValue(),
                    result = true;

                if (this._bRequired && !value.length) {
                    result = false;
                }

                if (!result) {
                    core.dispatchEvent(this, 'error');
                }
                return result;
            },
            onchange: function () {
                this.refreshValue();
            },
            init: function () {
                ui.InputControl.prototype.init.call(this);
                // this.refreshValue();
            },
            refreshValue: function () {
                var value = this._uFiles.getItems().map(function (item) { return item._oItem.id; }).join(',');
                this.getInput().value = value;
                dom[value === '' ? 'addClass' : 'removeClass'](this.getMain(), 'placeholder');
            },
            getFormValue: function () {
                var value = this.getValue();
                return value ? value.split(',') : [];
            }
        }
    );
    // 音乐人选择页面控件
    mao.ui.MusicPeoplePage = core.inherits(
        ui.Control,
        function (el, options) {
            ui.Control.call(this, el, options);
            this._aChildren = [];

            var children = dom.children(el);
            this._uSearch = core.$fastCreate(this.SearchText, dom.first(children[0]), this, {});
            dom.addClass(this._uSearch.getMain(), ' ui-search-text ui-text ui-input ');

            this._uList = core.$fastCreate(this.List, children[1], this, {
                view: 'musicPeopleList',
                initRefresh: true,
                reqUrl: '/erp-management/customer/musician/select-list-page?musicPeoplePageSearchForm',
                customEmpty: true
            });

            var lastEl = dom.last(el);
            this._eItemLabel = dom.first(lastEl);
            this._uItemList = core.$fastCreate(this.ItemList, dom.children(lastEl)[1], this);
            this._uSave = core.$fastCreate(this.Save, dom.last(lastEl), this);
            if (options.data) {
                options.data.forEach(function (item) {
                    this._uItemList.add(item);
                }, this);
                this._uList._oOptions.ids = options.data.map(function (item) { return item.value; });
            }
        },
        {
            SearchText: core.inherits(
                mao.ui.SearchText,
                {
                    searchHandler: function () {
                        ecui.dispatchEvent(this.getParent()._uList, 'refresh');
                    }
                }
            ),
            List: core.inherits(
                mao.ui.AppListView,
                {
                    Item: core.inherits(
                        mao.ui.AppListView.prototype.Item,
                        function (el, options) {
                            mao.ui.AppListView.prototype.Item.call(this, el, options);
                            this._uCheckbox = core.$fastCreate(this.MusicPeople, dom.first(el), this, { item: options.item, checked: options.checked });
                        },
                        {
                            MusicPeople: core.inherits(
                                ui.Checkbox,
                                function (el, options) {
                                    this._oItem = options.item;
                                    ui.Checkbox.call(this, el, options);
                                },
                                {
                                    onchange: function (event) {
                                        var parent = this.getParent().getParent().getParent();
                                        event.checked = this.isChecked();
                                        event.item = this._oItem;
                                        ecui.dispatchEvent(parent, 'itemchange', event);
                                    }
                                }
                            )
                        }
                    )
                }
            ),
            ItemList: core.inherits(
                ui.MListView,
                {
                    Item: core.inherits(
                        ui.Item,
                        function (el, options) {
                            dom.addClass(el, 'people-item');
                            if (options.headPortrait) {
                                el.innerHTML = util.stringFormat('<img src="{0}" /><span class="name">{1}</span><span class="close"></span>', options.headPortrait, options.name);
                            } else {
                                el.innerHTML = util.stringFormat('<div class="head">{0}</div><span class="name">{1}</span><span class="close"></span>', options.name.slice(0, 1), options.name);
                            }
                            ui.Item.call(this, el, options);
                            this._oItem = Object.assign({}, options, { parent: undefined, primary: undefined, uid: undefined });

                            this._uClose = core.$fastCreate(this.Close, dom.last(el), this, options);
                        },
                        {
                            Close: core.inherits(
                                ui.Control,
                                {
                                    onclick: function (event) {
                                        this.getParent().remove();
                                    }
                                }
                            ),
                            remove: function () {
                                var parent = this.getParent();
                                var item = this._oItem;
                                parent.remove(this);
                                ecui.dispatchEvent(parent.getParent(), 'itemclear', { item: item });
                            },
                            getData: function () {
                                return this._sData;
                            }
                        }
                    )
                }
            ),
            Save: core.inherits(
                ui.Control,
                {
                    onclick: function () {
                        ecui.dispatchEvent(this.getParent(), 'confirm');
                    }
                }
            ),
            onconfirm: function (event) {
                ecui.dispatchEvent(this.getParent(), 'confirm', { items: this._uItemList.getItems().map(function (item) { return item._oItem; }) });
            },
            onitemclear: function (event) {
                this._uList.getItems().forEach(function (item) {
                    if (item._uCheckbox._oItem.id === event.item.id) {
                        item._uCheckbox.setChecked(false);
                    }
                });
                this.refreshStatus();
            },
            onitemchange: function (event) {
                var itemList = this._uItemList;
                if (event.checked) {
                    itemList.add(event.item);
                } else {
                    itemList.remove(itemList.getItems().find(function (item) { return item._oItem.id === event.item.id; }));
                }
                this.refreshStatus();
            },
            onready: function () {
                this.refreshStatus();
            },
            refreshStatus: function () {
                var items = this._uItemList.getItems();
                var len = items.length;
                this._uList._oOptions.ids = items.map(function (item) { return item._oItem.value || item._oItem.id; });

                dom[len ? 'removeClass' : 'addClass'](dom.parent(this._eItemLabel), 'ui-placeholder')
                this._eItemLabel.innerHTML = len ? '已选择：' : '请选择音乐人';
            }
        }
    );
    // 音乐人编辑控件
    mao.ui.MusicPople = core.inherits(
        mao.ui.Pople,
        'ui-music-people',
        function (el, options) {
            options.labelFormat = '{0}个音乐人';
            options.view = 'music-people-page';
            mao.ui.Pople.call(this, el, options);
        },
        {
            Add: core.inherits(
                ui.Control,
                {
                    onclick: function () {
                        var parent = this.getParent(),
                            uPeoples = parent.getPeoples(),
                            musics = uPeoples._aChildren.map(function (item) { return item._sData }),
                            ids = uPeoples._aChildren.map(function (item) { return item._sData.id });

                        ecui.esr.showSelect(ecui.esr.getEngine().render(parent._sView, { mutil: parent._bMutil, value: musics, ids: ids }), function (event) {
                            ecui.dispatchEvent(parent, 'confirm', event);
                        }.bind(this), parent._sTitle);
                    }
                }
            ),
            onconfirm: function (event) {
                var uPeoples = this._uPeoples;
                uPeoples.removeAll();
                uPeoples.add(event.items.map(function (item) {
                    return { 'value': item.id, 'name': item.name, 'headPortrait': item.headPortrait };
                }));
                ecui.dispatchEvent(this, 'change', event);
            }
        }
    );
    mao.ui.CommentSave = core.inherits(
        ecui.ui.Text,
        function (el, options) {
            ecui.ui.Text.call(this, el, options);
            this._uOperates = [];
            dom.children(dom.last(el)).forEach(function (item) {
                if (item.tagName === 'INPUT' || item.tagName === 'STRONG') {
                    this._uOperates.push(core.$fastCreate(this.Operate, item, this, core.getOptions(item)));
                }
            }.bind(this));
            this._uSubmit = core.$fastCreate(this.Submit, dom.children(el)[1], this, options);
        },
        {
            action: undefined,
            Operate: ecui.inherits(
                ecui.ui.Control,
                function (el, options) {
                    ecui.ui.Control.call(this, el, options);
                    this._sAction = options.action;
                    this._bBack = options.back;
                },
                {
                    onclick: function (event) {
                        var parent = this.getParent(),
                            value = parent.getValue();
                        parent.action = this._sAction;
                        var elements = parent.getInput().form.elements;
                        if (elements.action) {
                            elements.action.value = this._sAction;
                        } else {
                            elements.auditStatus.value = this._sAction;
                        }
                        // event.preventDefault();
                        // core.setFocused(parent);
                        // parent.getInput().focus();
                        // return false;
                    }
                }
            ),
            Submit: core.inherits(
                ecui.ui.Button,
                {
                    onclick: function () {
                        ecui.dispatchEvent(this.getParent(), 'submit');
                    }
                }
            ),
            onkeydown: function (event) {
                if (event.which === 13) {
                    util.timer(function () {
                        // ecui.dispatchEvent(this, 'blur');
                        core.setFocused();
                    }, 0, this);
                    ecui.dispatchEvent(this, 'submit');
                }
            },
            onsubmit: util.blank,
        }
    );
    /**
     * 操作按钮控件。
     * 筛选框动态的响应用户的输入并提供选择，用户不输入时 filter 表现与普通的输入框相同。
     * options 属性：
     * bType   业务类型，1：合同；2：订单；3：票务；4：结算单 5：厂牌结算单；6：单据、厂牌项目
     * cType   操作类型，-1：删除，0：撤销，1：提交，2：驳回，3：通过，4：中止
     * content 提示信息
     * tip     操作完提示信息
     * @control
     */
    mao.ui.ApprovalSubmitBtn = core.inherits(
        ui.Button,
        function (el, options) {
            ui.Button.call(this, el, options);
            this._sBType = options.bType;
            this._sCType = options.cType;
            this._sContent = options.content;
            this._sTip = options.tip;
        },
        {
            onkeydown: function (event) {
                if (event.which === 13) {
                    util.timer(function () {
                        // ecui.dispatchEvent(this, 'blur');
                        core.setFocused();
                    }, 0, this);
                    ecui.dispatchEvent(this, 'submit');
                }
            },
            onclick: function (event) {
               ecui.dispatchEvent(this, 'submit');
            },
            onsubmit: function () {
                 if (this._bRequest) {
                    return;
                }
                var form = this.getForm(),
                    elements = form.elements,
                    data = {},
                    text = ['撤销', '提交', '拒绝', '同意', '中止'], // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                    valid = ecui.esr.parseObject(form, data, false);
                    urlMap = [
                        {},
                        {
                            'action': '/erp-management/contract/action',
                            'delete': '/erp-management/contract/delete'
                        },
                        {
                            'action': '/erp-management/venue/order/action',
                            'delete': '/erp-management/venue/order/delete'
                        },
                        {
                            'action': '/erp-management/project/round/cancle-ticket/' + data.id,
                            'delete': '/erp-management/project/round/del-ticket'
                        },
                        {
                            'action': '/erp-management/finance/play/income/action',
                            'delete': '/erp-management/finance/play/income/delete'
                        },
                        {
                            'action': '/erp-management/sponsor/finance/play/income/action',
                            'delete': '/erp-management/sponsor/finance/play/income/delete'
                        },
                        {
                            'action': '/erp-management/audit/operate',
                            'delete': '/erp-management/sponsor/finance/play/income/delete'
                        }
                    ];

                if (elements.action) {
                    elements.action.value = this._sCType;
                    data.action = this._sCType;
                } else if (elements.auditStatus) {
                    elements.auditStatus.value = this._sCType;
                    data.auditStatus = this._sCType;
                }
                this._bRequest = true;
                ecui.esr.setData('approvalParam', data);
                ecui.confirm(
                    this._sContent || '是否' + text[this._sCType],
                    function () {
                        ecui.esr.request(
                            'data@JSON ' + urlMap[this._sBType][this._sCType === '-1' ? 'delete' : 'action'] + '?${approvalParam}',
                            function () {
                                this._bRequest = false;
                                var code = ecui.esr.getData('data_CODE');
                                if (code === 0) {
                                    ecui.tip('warn', this._sTip);
                                    this.afterActionRequest();
                                }
                            }.bind(this),
                            function () {
                                this._bRequest = false;
                                return false;
                            }.bind(this)
                        );
                    }.bind(this),
                    function () {
                        this._bRequest = false;
                    }.bind(this)
                );
            },
            afterActionRequest: function () {
                // history.go(-1);
                var route = ecui.esr.findRoute(this.getMain());
                delete route.CACHE;
                ecui.esr.reload();
            }
        }
    );
    mao.ui.VenueSelected = core.inherits(
        ecui.ui.MPanel,
        {
            ondragmove: function () {
                var scrollTop = Math.abs(this.getY()),
                    fixedTitle = dom.first(dom.first(this.getBody())),
                    title;

                if (!this._eTitle) {
                    this.getTitleTop();
                }
                if (scrollTop > this._eTitle[0].top) {
                    dom.removeClass(fixedTitle, 'ui-hide');
                } else if (!dom.hasClass(fixedTitle, 'ui-hide')) {
                    dom.addClass(fixedTitle, 'ui-hide');
                }

                for (var i = 0, item; item = this._eTitle[i++]; ) {
                    if (scrollTop >= item.top) {
                        if (this._eTitle[i] && scrollTop < this._eTitle[i].top) {
                            title = item;
                            fixedTitle.innerHTML = title.el.innerHTML;
                            break;
                        }
                    } else {
                        break;
                    }
                }
                fixedTitle.style.transform = 'translateY(' + scrollTop + 'px)';
            },
            getTitleTop: function () {
                this._eTitle = [];
                var items = dom.children(dom.first(this.getBody()));
                for (var i = 2, item; item = items[i++]; ) {
                    if (dom.hasClass(item, 'venue-title')) {
                        this._eTitle.push({ el: item, top: item.offsetTop});
                    }
                }
            }
        }
    );

    mao.ui.SelectSaveBtn = ecui.inherits(
        ecui.ui.Button,
        'ui-select-save-btn',
        {
            $click: function () {
                var layer = this.findControl(ecui.esr.AppLayer);
                var radios = core.query(function (item) {
                    return item instanceof ui.Radio && item.isChecked() && ecui.dom.contain(layer.getMain(), item.getMain());
                });
                if (radios.length) {
                    core.dispatchEvent(item, 'confirm', { 'item': Object.assign(radios[0]._oItem, { _sText: radios[0]._sText, _sValue: radios[0]._sValue }) });
                }
            }
        }
    );
    // 场馆选择 - 单选 - 按钮
    mao.ui.VenueRadioEdit = core.inherits(
        ecui.ui.Radio,
        function (el, options) {
            ecui.ui.Radio.call(this, el, options);
            this._sValue = options.value;
            this._sText = options.text;
        },
        {
            $click: function (event) {
                ecui.ui.Radio.prototype.$click.call(this, event);
                var parent = this;
                for (; parent = parent.getParent(); ) {
                    if (parent instanceof ecui.esr.AppLayer) {
                        break;
                    }
                }
                core.dispatchEvent(
                    parent,
                    'confirm',
                    {
                        'value': this.getValue(),
                        'item': this,
                        'text':  this.text,
                        'showNum': 1
                    }
                );
            },
            getText: function () {
                return this._sText;
            }
        }
    );
    mao.ui.SelectRadio = ecui.inherits(
        ecui.ui.Radio,
        function (el, options) {
            ecui.ui.Radio.call(this, el, options);
            this._sValue = options.value;
            this._sText = options.text;
            this._oItem = options.item;
        },
        {
            $click: function (e) {
                ecui.ui.Radio.prototype.$click.call(this, e);
                if (this.getParent() && (this.getParent().getParent() instanceof ui.TreeView)) {
                    e.stopPropagation();
                }
                var layer = this.findControl(ecui.esr.AppLayer);
                var radios = core.query(function (item) {
                    return item instanceof ui.Radio && item.isChecked() && ecui.dom.contain(layer.getMain(), item.getMain());
                });
                if (radios.length) {
                    core.dispatchEvent(layer, 'confirm', { 'item': Object.assign(radios[0]._oItem, { _sText: radios[0]._sText, _sValue: radios[0]._sValue }) });
                }
            },
            getText: function () {
                return this._sText;
            }
        }
    );
    mao.ui.SelectCheckbox = ecui.inherits(
        ecui.ui.Checkbox,
        function (el, options) {
            ecui.ui.Checkbox.call(this, el, options);
            this._sValue = options.value;
            this._sText = options.text;
            this._oItem = options.item;
        },
        {
            getText: function () {
                return this._sText;
            }
        }
    );
    mao.ui.MutilSelectSaveBtn = ecui.inherits(
        ecui.ui.Button,
        'ui-select-save-btn',
        {
            $click: function () {
                var layer = this.findControl(ecui.esr.AppLayer);
                var checkboxs = core.query(function (item) {
                    return item instanceof ui.Checkbox && item.isChecked() && ecui.dom.contain(layer.getMain(), item.getMain());
                });
                core.dispatchEvent(layer, 'confirm', { 'item': checkboxs.map(function (item) { return Object.assign(item._oItem, { _sText: item._sText, _sValue: item._sValue }); }) });
            }
        }
    );
    // 公共的 过滤单选 控件
    mao.ui.FilterRadio = ecui.inherits(
        ecui.ui.Radio,
        function (el, options) {
            ecui.ui.Radio.call(this, el, options);
            this._sValue = options.value;
            this._sText = options.text;
        },
        {
            $click: function (e) {
                ecui.ui.Radio.prototype.$click.call(this, e);
                for (var parent = this.getParent(); parent; parent = parent.getParent()) {
                    if (parent instanceof ecui.ui.Tab) {
                        stableFormData(parent.getSelected());
                        break;
                    }
                }

                refreshListView(this);
            },
            getText: function () {
                return this._sText;
            }
        }
    );
    // 筛选：区间选择控件
    mao.ui.Slider = ecui.inherits(
        ecui.ui.InputControl,
        function (el, options) {
            ecui.ui.InputControl.call(this, el, options);
            this.scale = JSON.parse(options.scale);

            this._eInput = el.getElementsByTagName('INPUT')[0];
            this._eToast = el.children[1].children[1];
            this._sFlag = options.flag;

            var slider = ecui.dom.create('DIV', {className: 'ui-couple-slider'});
            el.insertBefore(slider, el.children[el.children.length - 1]);
            this._uSlider = ecui.$fastCreate(this.CoupleSlider, slider, this, {segment: 50});
        },
        {
            CoupleSlider: ecui.inherits(
                ecui.ui.CoupleSlider,
                {
                    onchange: function (event) {
                        var parent = this.getParent(),
                            min = Math.round(event.min),
                            max = Math.round(event.max),
                            scale = parent.scale, // 定义的刻度
                            start = '',
                            end = '',
                            toast = '';

                        if ((min === 0 && max === scale.length - 1) || (min === max && max === scale.length - 1)) { // 0-15 || 15-15 || 0-0
                            start = '';
                            end = '';
                            toast = '不限';
                        } else if (min === max && max !== scale.length - 1) { // 1-1、14-14
                            start = min;
                            end = max;
                            toast = this.toFixed(min) + '场';
                        } else { // 1-15、2-14
                            if (min !== 0 && max === scale.length - 1) { // 1-15
                                start = min;
                                end = '';
                            } else { // 0-14、2-15、2-14
                                start = min;
                                end = max;
                            }
                            toast = scale[this.toFixed(min)] + '-' + scale[this.toFixed(max)] + (this.toFixed(max) === scale.length - 1 ? '' : '场');
                        }
                        parent._eInput.value = start + ',' + end;
                        parent._eToast.innerHTML = toast;
                    },
                    toFixed: function (value) {
                        return value === 0 ? 0 : Math.ceil(value / 2);
                    }
                }
            ),
            $initStructure: function (width, height) {
                ecui.ui.CoupleSlider.prototype.$initStructure.call(this, width, height);
                // this.setValue(0, (this.scale.length - 1) * 2);
            },
            setValue: function (min, max) {
                var scale = this.scale; // 定义的刻度
                if (!this.$$border) {
                    this.handler = ecui.util.timer(function () {
                        if (this.$$border) {
                            this.handler();
                            if ((!min && !max) || (min === max && +max === scale.length - 1)) {
                                min = 0;
                                max = scale.length - 1;
                            } else if (min > 0 && max === '') {
                                max = scale.length - 1;
                            }
                            this._uSlider.setValue(+min, +max);
                            ecui.dispatchEvent(this._uSlider, 'change', {min: min, max: max});
                        }
                    }, -100, this);
                } else {
                    if ((!min && !max) || (min === max && +max === scale.length - 1)) {
                        min = 0;
                        max = scale.length - 1;
                    } else if (min > 0 && max === '') {
                        max = scale.length - 1;
                    }
                    this._uSlider.setValue(+min, +max);
                    ecui.dispatchEvent(this._uSlider, 'change', {min: min, max: max});
                }
            },
            onready: function () {
                this.setValue(0, (this.scale.length - 1) * 2);
                this._eInput.value = 0 + ',' + (this.scale.length - 1) * 2;
            },
            getValue: function () {
                return this._eInput.value;
            },
            getFormValue: function () {
                return this._eInput.value.split(',').map(function (item) { return +item; });
            },
            getFlag: function () {
                return this._sFlag;
            }
        }
    );
    // 选择页面 确认按钮 控件
    mao.ui.FilterSingleSelectSure = core.inherits(
        ecui.ui.Control,
        function (el, options) {
            ecui.ui.Control.call(this, el, options);
            this.showtext = options.showtext;
            this.shownum = options.shownum;
            this.outOfTab = options.outOfTab;
        },
        {
            $click: function (event) {
                ecui.ui.Control.prototype.$click.call(this, event);
                var text,
                    popupButton = this.findControl(mao.ui.PopupButton),
                    tab = this.findControl(ui.Tab);
                if (popupButton) {
                    popupButton.getPopup().hide();
                    core.dispatchEvent(
                        popupButton,
                        'confirm'
                    );
                    return;
                }
                if (tab) {
                    text = stableFormData(tab.getSelected());
                }
                // for (var parent = this.getParent(); parent; parent = parent.getParent()) {
                //     if (parent instanceof ecui.ui.Tab) {
                //         text = stableFormData(parent.getSelected());
                //         break;
                //     }
                // }

                core.dispatchEvent(
                    tab,
                    'confirm',
                    {
                        'selected': tab.getSelected(),
                        'text':  text.join(','),
                        'showNum': this.shownum
                    }
                );
                // parent.setSelected(0);
                refreshListView(this, this.outOfTab);
            }
        }
    );

    function stableFormData(control) {
        var inputs = control.getContainer().getElementsByTagName('INPUT'),
            text = [];
        Array.prototype.slice.call(inputs).forEach(function (item) {
            if (item.getControl) {
                var subControl = item.getControl();
                if (item.type === 'text' && item.value !== '') {
                    setStableFormValue(control, subControl, text);
                } else if (item.type === 'radio') {
                    if (subControl.isChecked && subControl.isChecked()) {
                        setStableFormValue(control, subControl, text);
                    }
                }
            } else {
                //TODO 不是ecui控件的，以后再说
            }
        });
        return text;
    }
    function setStableFormValue(control, subControl, text) {
        if (!control.value) {
            control.value = {};
        }
        control.value[subControl.getName()] = subControl.getValue();
        var textArray = subControl.getMain().outerHTML.replace(/\s+/g, '').match(/>[^<]+/g);
        var temp = '';
        if (textArray && textArray.length > 0) {
            if (textArray[0].length > 1) {
                temp = textArray[0].slice(1);
            }
        }
        text.push(temp);
    }
    /**
     * [refreshListView description]
     * @param  {[type]} control [description]
     * @param  {[type]} outOfTab   listview是否在tab里面
     * @return {[type]}         [description]
     */
    function refreshListView(control, outOfTab) {
        for (var parent = control.getParent(); parent; parent = parent.getParent()) {
            if (parent instanceof ecui.ui.Tab) {
                parent.setSelected(0);
                if (outOfTab) {
                    parent = parent.getParent();
                }
                break;
            }
        }
        var listView = ecui.query(
            function (item) {
                return item instanceof ecui.ui.MListView && parent.contain(item);
            }
        )[0];
        if (listView) {
            ecui.dispatchEvent(listView, 'refresh');
        }
    }
    // 多级选择联动 控件
    mao.ui.MMultiSelect = core.ui.MMultilevelSelect;
    var citySelectInstance;
    function getCITYS(type) {
        var code,
            key,
            key2,
            citys,
            area,
            item,
            item2,
            PROVINCE = {},
            CITY = {},
            AREA = {};
        for (code in mao.cities) {
            if (mao.cities.hasOwnProperty(code)) {
                if (code.slice(2) === '0000') {
                    PROVINCE[code] = mao.cities[code];
                } else if (code.slice(4) === '00') {
                    if (!CITY[code.slice(0, 2) + '0000']) {
                        CITY[code.slice(0, 2) + '0000'] = {};
                    }
                    CITY[code.slice(0, 2) + '0000'][code] = mao.cities[code];
                } else {
                    if (!AREA[code.slice(0, 4) + '00']) {
                        AREA[code.slice(0, 4) + '00'] = {};
                    }
                    AREA[code.slice(0, 4) + '00'][code] = mao.cities[code];
                }
            }
        }
        // debugger
        var CITYS = [];
        for (code in  PROVINCE) {
            citys = {
                value: code,
                code: PROVINCE[code],
                children: []
            };
            item = CITY[code];
            for (key in item) {
                if (item.hasOwnProperty(key)) {
                    if (type === '3') {
                        area = {
                            value: key,
                            code: item[key],
                            children: []
                        };
                        item2 = AREA[key];
                        for (key2 in item2) {
                            if (item2.hasOwnProperty(key2)) {
                                area.children.push({
                                    value: key2,
                                    code: item2[key2]
                                });
                            }
                        }
                        if (area.children.length <= 0) {
                            delete area.children;
                        }
                        citys.children.push(area);
                    } else if (type === '2') {
                        citys.children.push({
                            value: key,
                            code: item[key]
                        });
                    }
                }
            }
            if (citys.children.length <= 0) {
                delete citys.children;
            }
            CITYS.push(citys);
        }
        return CITYS;
    }
    var CitySelect = ecui.inherits(
        ui.MMultilevelSelect,
        true,
        function (el, options) {
            ui.MMultilevelSelect.call(this, el, options);
            this._nLevel = options.level;
        },
        {
            init: function () {
                ui.MMultilevelSelect.prototype.init.call(this);
                var self = this;
                util.timer(function () {
                    // 目前是两级，如果用3级传3
                    if (self._nLevel === 2) {
                        citySelectInstance.setData(getCITYS('2'));
                    } else {
                        citySelectInstance.setData(getCITYS('3'));
                    }
                    var owner = ecui.esr.getGlobal().cityOwner;
                    if (owner) {
                        defaultSelect(owner);
                    }
                }, 0); //延后执行setData方法
            },
            setSelected: function (value) {

            }
        }
    );
    var setSelectInView = function (item) {
        return function () {
            item.getMain().scrollIntoViewIfNeeded();
        };
    };
    var defaultSelect = function (owner) {
        var value = owner.getValue();
        var region = [value.slice(0, 2), value.slice(0, 4), value].map(function (item) { return (item + '000000').slice(0, 6); }).filter(function (item) { return item !== '000000'; });
        console.log(region);
        if (region.length) {
            region.forEach(function (item, i) {
                var select = citySelectInstance.getSelect(i);
                var items = select.getItems();
                select.getItems().forEach(function (_item) {
                    if (_item._sValue === item) {
                        select.setSelected(null);
                        select.setSelected(_item);
                        util.timer(function () {
                            _item.getMain().scrollIntoViewIfNeeded();
                            ecui.$('AppSelectContainer').scrollLeft = 0;
                        }, 500);
                    }
                });
            });
        } else {
            ecui.util.timer(function () {
                citySelectInstance.getSelect(0).setSelected(null);
            }, 0);
        }
    };
    mao.ui.popCitySelect = function (control, level) {
        citySelectInstance = ecui.getSingleton(CitySelect, function () {
            return dom.create(
                {
                    className: 'ui-popup ui-city',
                    innerHTML: level === 2 ? '<ul></ul><ul></ul>' : '<ul></ul><ul></ul><ul></ul>'
                }
            );
        }, '', {level: level});
        citySelectInstance.onrequest = function (event) {
            event.data.forEach(function (item) {
                item['#text'] = item.code;
            });
        };
        ecui.esr.showSelect(citySelectInstance, function (event) {
            var text = [], value;
            event.items.forEach(function (item) {
                text.push(item.getContent());
                value = item.getValue();
            });
            control.setText(text);
            control.setValue(value);
        }, '城市选择');

        // 重置选择项
        defaultSelect(control);
    };
    mao.ui.CitySelect = ecui.inherits(
        ecui.ui.InputControl,
        function (el, options) {
            options = Object.assign({ 'readOnly': true }, options);
            options = Object.assign({ 'inputType': 'text' }, options);
            ecui.ui.InputControl.call(this, el, options);
            this._eText = ecui.dom.insertBefore(dom.create({ className: 'ui-city-text', innerHTML: options.text }), this.getInput());
            this._nLevel = options.level || 2;
            if (!this.getFormValue()) {
                this.alterStatus('+placeholder');
                this._eText.innerHTML = this.getInput().placeholder;
            }
        },
        {
            clearTimer: util.blank,
            $click: function () {
                ecui.esr.setGlobal('cityOwner', this);
                mao.ui.popCitySelect(this, this._nLevel);
            },
            setText: function (text) {
                this._eText.innerHTML = text;
            },
            setValue: function (value) {
                if (value === '0' || !value) {
                    this.alterStatus('+placeholder');
                    this._eText.innerHTML = this.getInput().placeholder;
                    return;
                }
                this._eText.innerHTML = ecui.ui.BCities.prototype.getCity(value).join('-');
                this.getInput().value = value;
                this.alterStatus('-placeholder');
            },
            getText: function () {
                return this._eText.innerHTML;
            }
        }
    );

    // 表单选择select
    mao.ui.MPopSelect = ecui.inherits(
        ecui.ui.MSelect,
        function (el, options) {
            ecui.ui.MSelect.call(this, el, options);
            this._sTitle = options.title;
            this._sValue = options.value;
            if (this._sValue) {
                this.setValue(this._sValue);
            }
        },
        {
            $error: ecui.util.blank,
            onerror: function () {
                ecui.tip('warn', '请选择' + this._sTitle);
            },
            setValue: function (value) {
                var hasItem = this.getItems().some(function (item) {
                    return item.getValue() === value;
                });
                ecui.ui.MSelect.prototype.setValue.call(this, hasItem ? value : '');
            }
        }
    );
    mao.ui.InputGroup = ecui.inherits(
        ecui.ui.InputGroup,
        function (el, options) {
            ecui.ui.InputGroup.call(this, el, options);
            this._sLabel = options.label;
            this._bRequired = options.required;
            this._sTip = options.tip;
        },
        {
            /**
             * 控件组格式校验错误的默认处理。
             * @event
             */
            $error: function () {
                // ecui.ui.InputGroup.prototype.$error.call(this);
                if (this._sTip) {
                    ecui.tip('warn', this._sTip);
                }
            },

            /**
             * @override
             */
             init: function () {
                ecui.ui.InputGroup.prototype.init.call(this);
                var el = this.getBody();

                if (this._bRequired) {
                    dom.toArray(el.querySelectorAll('.ui-input')).forEach(function (item) {
                        item = item.getControl();
    
                        item._oRegExp = new RegExp('^.+$');
                    });
                }
                if (this._sLabel) {
                    el.insertBefore(
                        dom.create(
                            'DIV',
                            { className: 'ui-input-label', innerHTML: (this._bRequired ? '<span class="ui-input-required">*</span>' : '') + this._sLabel }
                        ),
                        el.firstChild
                    );
                }
                this._eTip = el.appendChild(dom.create('DIV', { className: 'ui-input-tip' }));
            }
        }
    );
    mao.ui.Submit = ecui.inherits(
        ecui.ui.Button,
        {
            request: function (url, onsuccess, onerror) {
                this.disable();
                ecui.esr.request(url, function () {
                    this.enable();
                    onsuccess.call(this);
                }.bind(this), function (err) {
                    this.enable();
                    if (onerror) {
                        onerror.call(this, err);
                    } else {
                        onsuccess.call(this);
                    }
                }.bind(this));
            }
        }
    );
    mao.ui.Checkbox = ecui.inherits(
        ecui.ui.Checkbox,
        {
            getFormValue: function () {
                return this.isChecked() ? this.getValue() : '0';
            },
            isFormChecked: function () {
                return true;
            }
        }
    );

    /**
     * 操作按钮控件。
     * 筛选框动态的响应用户的输入并提供选择，用户不输入时 filter 表现与普通的输入框相同。
     * options 属性：
     * eType   业务类型，1：合同；2：订单；3：结算单；4：厂牌结算单 5：艺人详情；6：出库单；7：单据；8：厂牌项目
     * cType   操作类型，-1：删除，0：撤销，1：提交，2：驳回，3：通过，4：中止
     * tip     操作玩提示信息
     * @control
     */
    mao.ui.QuickApprovalSubmitBtn = core.inherits(
        ui.Button,
        function (el, options) {
            ui.Button.call(this, el, options);
            this._sOptId = options.optId;
            this._sEType = options.eType;
            this._sCType = options.cType;
            this._sTip = options.tip;
        },
        {
            onkeydown: function (event) {
                if (event.which === 13) {
                    this.getInput().blur();
                    ecui.dispatchEvent(this, 'blur');
                    ecui.dispatchEvent(this, 'submit');
                }
            },
            onclick: function (event) {
                ecui.dispatchEvent(this, 'submit');
                event.stopPropagation();
            },
            onsubmit: function () {
                if (this._bRequest) {
                    return;
                }
                var text = ['', '', '拒绝', '同意']; // 0-撤销 1-提交 2-驳回 3-通过 4-中止
                var urlMap = [
                    '',
                    '/erp-management/contract/action',
                    '/erp-management/venue/order/action',
                    '/erp-management/finance/play/income/action',
                    '/erp-management/sponsor/finance/play/income/action',
                    '/erp-management/artist/action',
                    '/erp-management/artist/stock/action',
                    '/erp-management/audit/operate',
                    '/erp-management/audit/operate'
                ];

                this._bRequest = true;
                ecui.confirm(
                    '是否' + text[this._sCType],
                    function () {
                        ecui.esr.request(
                            util.stringFormat('data@JSON {0}?id={1}&action={2}', urlMap[this._sEType], this._sOptId, this._sCType),
                            function () {
                                this._bRequest = false;
                                var data = ecui.esr.getData('data');
                                if (data instanceof Object) {
                                    ecui.tip('warn', this._sTip);
                                    var item = this.getParent();
                                    if (item && item.getParent() && item.getParent().remove) {
                                        item.getParent().remove(item);
                                    }
                                    ecui.dispatchEvent(this, 'complete');
                                    if (this.getParent()) {
                                        ecui.dispatchEvent(this.getParent(), 'complete');

                                        if (this.getParent().getParent()) {
                                            ecui.dispatchEvent(this.getParent().getParent(), 'complete');
                                        }
                                    }
                                }
                            }.bind(this),
                            function () {
                                this._bRequest = false;
                                return false;
                            }.bind(this)
                        );
                    }.bind(this),
                    function () {
                        this._bRequest = false;
                    }.bind(this)
                );
            }
        }
    );
}());